Page 1 of 1

How To Accomplish The Following...

Posted: Sat Sep 03, 2005 6:29 am
by DelphiLove
How to make text between 2 of the same characters become underlined?


Deleting should be taken into effect. For example say the char I wanted to look for is Chr(3) where Chr is Delphi's function.

The first one is the starting char and the second one is the matching. Think of it like HTML's bold tag only there's no distinction in the closing tag.

So you have

Chr(3) some text Chr(3) some more text

Then you'd get the following

Chr(3) some text Chr(3) some more text

If you deleted the closing tag then you should have

Chr(3) some text some more text

If you deleted the start tag then the closing tag becomes a start tag
some text Chr(3) some more text

Hope this is clear enough.

Posted: Sat Sep 03, 2005 5:08 pm
by Sergey Tkachenko
This is quite a complicated logic, there are no methods to make it simple.

General direction - in OnChange, use SearchText (or other method) to find the character, then use SetSelectionBounds, ApplyStyleConversion, InsertText.
Similar work is performed in the simple RichViewEdit-based syntax highlighter, see http://www.trichview.com/resources/

Posted: Wed Sep 07, 2005 6:20 am
by Guest
Ok I've tried this but no luck.

In OnChange, I store the old cursor position and then move the cursor position to the beginning. But what happens is that the the new text that fires OnChange, is being entered at position 0 instead of where the cursor position was original.

Also restoring the old cursor position isn't working for me. Can you provide some code, thanks.

Posted: Wed Sep 07, 2005 9:02 am
by Sergey Tkachenko
May be you call Format somewhere, and it resets the caret position to the beginning?
It's better to use functions from RVLinear.pas to store and restore the selection.

function RVGetLinearCaretPos(rve: TCustomRichViewEdit): Integer;
procedure RVSetLinearCaretPos(rve: TCustomRichViewEdit; LinearPos: Integer);

procedure RVGetSelection(rv: TCustomRichView; var SelStart, SelLength: Integer);
procedure RVSetSelection(rv: TCustomRichView; SelStart, SelLength: Integer);

Posted: Wed Sep 07, 2005 6:31 pm
by Guest
Awesome. I'll definitely make use of this as it's much better suited.

Thanks.