Advmemo

Hi,
I need a AdvMemo for a rather simple task: to display texts on a client from a remote datasnap server. Clients simply gets a dataset from the server and adds text lines from it on the advmemo. Works as a charm. Only problem is wordwrapping: some lines are 40 characters, others are 100 or 200 bytes long so I use wordwrap for the advmemo.
The gutter shows line numbers correctly. A long text may take 3 "virtual lines" and the gutter shows it correctly as one line with 2 additional sublines.

Example:
Gutter #1: "Mercedes"
Gutter #2: "Tesla X"
Gutter #3: "This line is long and is
wrapped and shown as 3 lines in the memo
as it is supposed to do
Gutter #4 " Next line is wrapped into
2 lines on the memo
Gutter #5: so on.....

If I want to grab a line, I click at it (e.g gutter #3's first line "This line is long and is" is then highlighted as expected but not the second and third sublines. I can live with that although it would be better if all 3 lines were automatically highlighted to show that they belong to the first line.

To the problem: with advmemo.lines[advmemo.activelines] I can catch one single line by clicking it. With advmemo1.WrappedLine[AdvMemo1.ActiveLine]) I catch all 3 lines of gutter #3. Works as a charm.

However, luck ends here. If I use advmemo1.WrappedLine[AdvMemo1.ActiveLine]) on gutter #4' lines and all subsequent lines thereafter, advmemo1.WrappedLine[AdvMemo1.ActiveLine]) seems to get out of sync. I get error "List index out of bounds" and result from it is only one line, not 2 as it should be for Gutter #4 in the example above. It seems that ActiveLine and gutter number somehow gets confused.

In my case, I like to address the lines via the Gutter field but there are no methods to do that.
Apprecitate your thoughts on how to tackle it.

Best reg Magnus B

You need to convert the display line index to the wrapped line index.
You can do this with:

var
  li: integer;
begin
  li := advmemo1.GetWrappedLineIndex(advmemo1.ActiveLine);
  ShowMessage(advmemo1.WrappedLine[li]);
end;

Thanks Bruno. It works beautifully

Best reg Magnus B