How To Accomplish The Following...

General TRichView support forum. Please post your questions here
Post Reply
DelphiLove

How To Accomplish The Following...

Post by DelphiLove » Sat Sep 03, 2005 6:29 am

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.

Sergey Tkachenko
Site Admin
Posts: 14764
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Sat Sep 03, 2005 5:08 pm

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/

Guest

Post by Guest » Wed Sep 07, 2005 6:20 am

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.

Sergey Tkachenko
Site Admin
Posts: 14764
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Wed Sep 07, 2005 9:02 am

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);

Guest

Post by Guest » Wed Sep 07, 2005 6:31 pm

Awesome. I'll definitely make use of this as it's much better suited.

Thanks.

Post Reply