Thanks Remy Lebeau. As said my current problem is on
Linux. Because there I did not find EM_SETSEL and EM_SCROLLCARET, I stole them from Windows (don't know if this is legal) and tried this 2 alternatives:
const EM_SCROLLCARET = 183; {from /.../fpcsrc/rtl/win/wininc/messages.inc}
MM.SelStart := MM.GetTextLen;
MM.SelLength := 0;
MM.Perform(EM_SCROLLCARET, 0, 0); // <-- the magic happens here
and:
const EM_SETSEL = 177; {from /.../fpcsrc/rtl/win/wininc/messages.inc}
EM_SCROLLCARET = 183; {from /.../fpcsrc/rtl/win/wininc/messages.inc}
var len: Integer;
len:=MM.GetTextLen;
MM.Perform(EM_SETSEL, len, len);
MM.Perform(EM_SCROLLCARET, 0, 0); // <-- the magic happens here
Unfortunately both alternatives did not work (did not scroll).
Thanks a lot Benny for your demo. The good news is, it works (Linux Ubuntu 24.04 GTK2 with Lazarus 3.4.0 and FPC 3.2.2). But you have a main difference: you scroll in Button3Click(), which is during ShowModal(), while I need scrolling
before calling ShowModal() as showed in my 1st post, because I want an automatic scroll and don't want the need to press a button each and every time to see the end of the Memo.
So I modified your demo by adding a FormCreate-Event:
procedure TForm1.FormCreate(Sender: TObject);
begin
writeln('FormCreate');
Memo1.Lines.LoadFromFile('unit1.pas');
Memo1.SelStart:= UTF8Length(Memo1.Caption);
// Memo1.SelLength:=0; // did not help
end;
Unfortunately now your demo does not work anymore.
In my real code (which is a common unit, used by many programs):
- the Form is created dynamically by CreateNew(Application)
- then everything else is initialized
- then the data is assigned from a StringList 'SL' to the Memo 'MM' via MM.Lines.Assign(SL)
- then ShowModal() is called.
How can I cause a scroll to the Memo's end
before calling ShowModal() - on Windows+Linux?