0

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.

Arnold
  • 4,578
  • 6
  • 52
  • 91
  • Please clarify what you mean. Does `display overflows` mean the `TMemo` has more lines than can be displayed without scrolling? Does `display added line` mean **scroll to the added line when it isn't visible**? Do you just want to scroll it into view, or do you want to also select the added line? – James L. Nov 19 '12 at 20:33
  • I want to scroll the lastly added line into view. Selection is not relevant. Caret is declared as `Caret: TCaretPosition`. – Arnold Nov 19 '12 at 20:41

2 Answers2

6

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.

James L.
  • 9,384
  • 5
  • 38
  • 77
  • This answer works fine. Both answers work equally well and I am very grateful to Jason and you. I decided to mark your answer as the correct one as you were the first to react. I know this is arbitrary but I simply don't know how to otherwise award the correct answer. – Arnold Nov 20 '12 at 18:39
4

You can set the value of the VScrollBar.Value property to its Max value. That will always scroll - or force the scrollbar - to the bottom of the Memo (ScrollBox).

eg:

Display.VScrollBar.Value := Display.VScrollBar.Max
Jason
  • 2,572
  • 3
  • 34
  • 41