I am getting 'Handle not allocated' errors. Did I miss something? [solved]ish lazarus / 21-General ---------------------------------------------------------------------- kensmith · 2022-02-21 00:34 I have: Code: [Select]  TScrollMessageForm = class(TForm)     DismissButton: TButton;     TopLabel: TLabel;     MessageMemo: TMemo;     procedure DismissButtonClick(Sender: TObject);     procedure FormCreate(Sender: TObject);     procedure FormResize(Sender: TObject);   private   public     IsForNotes : boolean;     NoteCount : longint;   end; In a related chunk of code I have Code: [Select]I := length(ScrollMessageForm.MessageMemo.Text)-1; ScrollMessageForm.MessageMemo.CaretPos := Point(0, I); or ( but not on the same attempt ) Code: [Select]ScrollMessageForm.MessageMemo.VertScrollBar.Position:=10000; Both of these attempts are landing me at a place that does a message like: "TWinControl.ScrollBy_WS: Handle not allocated. Press OK to ignore and risk data corruption. Press Abort to kill the program."  Did I miss a step? The intended purpose here is to scroll the memo to the last line I added and to have it work on Linux, Unix, Apple, Windows-95 thru Windows 13, on 32 bit, 64 bit and 128 bit versions etc.  For this reason I seriously want to avoid any OS dependent constructs. What this code is replacing has been in use for  about 30 years and I expect the new version to be used for about that long. Note: Before posting this, I spent all day searching for the answer with duckduckgo and got many suggested things that didn't work.  I am carrying on without the feature working to get the rest of the code written. ---------------------------------------------------------------------- Bart · 2022-02-21 17:15 At what point in time is this code called? Bart ---------------------------------------------------------------------- Red_prig · 2022-02-21 17:39 in general terms, this message means that you are trying to use the handle before the window is initialized. try checking with the ControlName.HandleAllocated function whether it is possible to perform actions with this. ---------------------------------------------------------------------- wp · 2022-02-21 18:02 Quote from: kensmith on February 21, 2022, 01:34:03 amThe intended purpose here is to scroll the memo to the last line I added and to have it work on Linux, Unix, Apple, Windows-95 thru Windows 13, on 32 bit, 64 bit and 128 bit versions etc.  Why so complicated? I checked the following code and the memo automatically scrolls to the last line added on Windows 11 and XP, as well as on Mac. It does not scroll in Linux/gtk2 and qt5, but moving the memo's SelStart to the end of the text helps here. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ButtonClick(Sender: TObject);begin  Memo1.Lines.Add('Line ' + IntToStr(Memo1.Lines.Count));  Memo1.SelStart := Length(Memo1.Text)-1;end; ---------------------------------------------------------------------- kensmith · 2022-02-21 23:23 Quote from: Bart on February 21, 2022, 06:15:56 pmAt what point in time is this code called? Bart The form is not yet shown when I do the first call to it. I want the last line to be on screen when it appears even if there are many lines. I update it as later stuff runs and use Application.ProcessMessages;  to allow the GUI to go. The same form is initially shown as a model dialog and then later is non-modal . I re-"Caption" the button from "Run" to "Abort" between the two cases. I hope that is clear. ---------------------------------------------------------------------- kensmith · 2022-02-21 23:34 Quote from: wp on February 21, 2022, 07:02:43 pmQuote from: kensmith on February 21, 2022, 01:34:03 amThe intended purpose here is to scroll the memo to the last line I added and to have it work on Linux, Unix, Apple, Windows-95 thru Windows 13, on 32 bit, 64 bit and 128 bit versions etc.  Why so complicated? I checked the following code and the memo automatically scrolls to the last line added on Windows 11 and XP, as well as on Mac. It does not scroll in Linux/gtk2 and qt5, but moving the memo's SelStart to the end of the text helps here. Note that you say it didn't scroll on " Linux/gtk2 and qt5". I want it to work on all systems. QuoteCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ButtonClick(Sender: TObject);begin  Memo1.Lines.Add('Line ' + IntToStr(Memo1.Lines.Count));  Memo1.SelStart := Length(Memo1.Text)-1;end; Code: [Select]  I := length(ScrollMessageForm.MessageMemo.Text)-1;   ScrollMessageForm.MessageMemo.SelStart := I; Seems to have it working on Linux. I will be calling this solved if it works on Windows-10 too. I don't have an Apple to try.