TAdvRichEditor: how to set caret to highlighted text?

Dear all

I want to highlight a string with
avRE.Highlight(sHLT, false); //sHLT: string;
in TAdvRichEditor. This works fine.

But how to get the caret of of the highlighted text?
Then I want to jump to the caret and make it visible by scrolling to the begin (or end) of of the highlighted text.

Up to now I was not able to realize that. Could you please help?

I'm not sure I understand your question. You say : 'get the caret of of the ..." and also jump to the begin or end of the highlighted text?
The caret is set with setting the selection via AdvRichEditor.SelStart: integer / AdvRichEditor.SelLength and then calling AdvRichEditor.SelectionToCaret;

Dear Mr. Fierens

Sorry for not having been clear enough with my problem. I try to describe it with the help of a screenshot (at the bottom of this post):

The text from an abstract has been added to a TAdvRicheditor (ARE) by sentences (the program uses a sentence end recognizer).
elt := ARE.AddText(sCellShow, DocFont.Size, DocFont.Name,[]); elt.LeftIndent := 20; {ARE: TAdvRichEditor; sCellShow: string; elt: TTextElement}
Then a multicolored string highlighting takes place:
if ARE.FindFirst(sHLTerm, false) then
begin
sSel := ARE.Caret.Element.Text;
ARE.SetSelectionFontName(DocFont.Name);
ARE.SetSelectionFontSize(DocFont.Size +1);
ARE.SetSelectionBold(true);
if RB_HLText.Checked then
ARE.SetSelectionUnderLine(true);
ARE.SetSelectionColor(ATextColor);
ARE.SetSelectionBkColor(ABgColor);
while ARE.FindNext do
begin

End;
ARE.ClearSelection;
ARE.SetCaret(0);
ARE.CaretToSelection;
ARE.EndUpdate;
{sHLTerm: string to be highlighted by a defined color}

Now I come closer to my issue. On the right side of the screenshot there is a so called Term
(Co-)Occurrence navigator. It shall help to quickly identify relevant parts in multipage text. The multi-colored highlight terms have been selected before navigating through documents and are shown in Row = 0 on the right.

Whenever there is a multicolored term in a sentence ( = TextElement), the a cell in the grid is colored with the appropriate color.
Hence you may quickly identify relevant parts for reading (instead of having to read all pages).

When clicking o a row on the navigator, I want to jump to the corresponding sentence ( = TextElement), which is highlighted by
advRE.UnHighlight;
advRE.Highlight(sHLT, false);
{advRE: TAdvRichEditor; sHLT: string: contains the complete sentence ( = TextElement)

Now we are there: I do not know how to jump / scroll by code to the page to the highlighted sentence (yellow in the screenshot), so that a user immediately can read the sentence of interest.

For performance reasons I did not use the FindFirst / FindNext function, but the Highlight() function of TAdvRichEditor.

AdvRichEditor.TopLeft: TPoint is the property with which you control the scroll position.
For all Elements in the document context, you can get the XY position. So, you can use these two things to scroll programmatically to the selection.
Attached demo shows this.Project1.zip (54.0 KB)

Dear Mr. Fierens

Your answer has been very helpful. This is the solution for the described issue. I am really grateful for your support!

Best regards

1 Like