Re: Delphi Memo: show last line


[ DelphiLand FAQ ]

Posted by webmaster Guido on April 01, 2004 at 15:59:51:

In Reply to: Delphi Memo: show last line posted by Johan p14205 on March 31, 2004 at 20:59:28:

: I use a Delphi TMemo component for feedback to the user. But when I add a certain number of lines to the memo, the last line is not visible anymore. I would like to keep the bottom of the memo visibile.
: How to make the TMemo scroll down automatically? Otherwise, the user has to click on the vertical scrollbar to see the last line, each time a line is added.
-------------------------------

When you add a line to a Memo, the cursor position ("caret") moves to the end of the Memo. However, the Memo does not scroll down automatically to show that position. In order to bring the line with the cursor into view, use this command:

SendMessage(Memo.Handle, EM_SCROLLCARET, 0, 0);

Examples:

To add a line to Memo1 and next make sure that this last line is visible:

  Memo1.Lines.Add('Extra line');
  SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); 

To add 5 lines to Memo1 and next make sure that the last line is visible:

procedure TForm1.Button1Click(Sender: TObject);
var
  i: integer;
begin
  for i := 1 to 5 do 
    Memo1.Lines.Add('Lines added: ' + IntToStr(i));
  SendMessage(Memo1.Handle, EM_SCROLLCARET, 0, 0); 
end;




Related Articles and Replies:




[ DelphiLand: free Delphi source code, tips, tutorials ]