Search code examples
delphitmemofiremonkey-fm2

How to show an arbitrary line in TMemo in FMX?


I add lines to a TMemo in Firemonkey and I want the line added to be scrolled into view when there are more lines than can be displayed in the TMemo. I cannot find how to do that. I tried

Display.Lines.Add (arg);
Caret.Line := Display.Lines.Count - 1;
Caret.Pos  := 0;
Display.CaretPosition := Caret;

but that did not help. The help was very limited so I am not sure what I am doing here.

Update

When trying out the code of the respondents I noticed I had tested the code example wrong. I apologize for that, my only excuse is that it was near midnight when I wrote and tested the code. The code above does work. I deleted the statement Display.CaretVisible := True; from the original code because this did not impact the behavior I desired.


Solution

  • Since you are are just appending the string via Lines.Add(), you can call Display.GoToTextEnd to scroll it to the end and show the just appended line.