Dynamic creation of the form of an event lazarus / 31-LCL ---------------------------------------------------------------------- Pe3s · 2021-10-30 19:30 Hello, if I create a form using code 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.BCButton5Click(Sender: TObject); var   myForm: TForm; begin   myForm := TForm.CreateNew(nil);   try     myForm.Width := 300;     myForm.Height := 300;      myForm.ShowModal;   finally     myForm.Free;    end;end;  how can I add onShow events to the form ? ---------------------------------------------------------------------- VTwin · 2021-10-30 20:56 Maybe this is not the answer you are looking for, but why not create a subclass of TForm using the Lazarus form editor? Rather than setting the properties in code, you can use the editor and object inspector to set properties, and add controls and events. The form can be created as needed, or auto-created. ---------------------------------------------------------------------- alpine · 2021-10-30 21:05 Quote from: Pe3s on October 30, 2021, 09:30:19 pmHello, if I create a form using code 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.BCButton5Click(Sender: TObject); var   myForm: TForm; begin   myForm := TForm.CreateNew(nil);   try     myForm.Width := 300;     myForm.Height := 300;      myForm.ShowModal;   finally     myForm.Free;    end;end;  how can I add onShow events to the form ? You need to have method of the Form1 (or some other class) of type TNotifyEvent, and then assign it to OnShow property like on line #14 below: 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.myFormOnShow(Sender: TObject);begin ...end; procedure TForm1.BCButton5Click(Sender: TObject); var   myForm: TForm; begin   myForm := TForm.CreateNew(nil);   try     myForm.Width := 300;     myForm.Height := 300;     myForm.OnShow := @myFormOnShow;     myForm.ShowModal;   finally     myForm.Free;    end;end; ---------------------------------------------------------------------- Pe3s · 2021-10-31 13:52 Thank you