Author Topic: Is it good idea TForm to have AfterShow event  (Read 1198 times)

daniel_sap

  • Full Member
  • ***
  • Posts: 115
Is it good idea TForm to have AfterShow event
« on: December 18, 2025, 01:46:02 pm »
Hi, in my projects I often send message after main form show.
This way I can show splash form or do other activities,
like opening the files passed in ParamStr(1)

Is it good idea TForm to have AfterShow event
What do you think

speter

  • Hero Member
  • *****
  • Posts: 535
Re: Is it good idea TForm to have AfterShow event
« Reply #1 on: December 18, 2025, 10:55:16 pm »
I generally set a boolean in form.create then use the form.activate event (checking the boolean to make sure the code only gets run once).

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Bart

  • Hero Member
  • *****
  • Posts: 5757
    • Bart en Mariska's Webstek
Re: Is it good idea TForm to have AfterShow event
« Reply #2 on: December 19, 2025, 10:28:30 pm »
Mostly I have an Application.QueueAsyncCall() in OnFormShow event to achieve this.

Bart

Xenno

  • Full Member
  • ***
  • Posts: 163
    • BS Programs
Re: Is it good idea TForm to have AfterShow event
« Reply #3 on: December 20, 2025, 09:45:20 am »
PostMessage at the end of onShow is enough. Not necessary, though.
Lazarus 4.6, Windows 10, https://www.youtube.com/@bsprograms
If I want to share, I give. If I want money, I sell. I don't set traps.

zeljko

  • Hero Member
  • *****
  • Posts: 1998
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Is it good idea TForm to have AfterShow event
« Reply #4 on: December 20, 2025, 12:53:45 pm »
PostMessage at the end of onShow is enough. Not necessary, though.

Application.QueueAsyncCall() works on all platforms and widgetsets, not sure that PostMessage works with all widgetsets.

jcmontherock

  • Sr. Member
  • ****
  • Posts: 363
Re: Is it good idea TForm to have AfterShow event
« Reply #5 on: December 20, 2025, 09:57:13 pm »
I found such routine:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.AfterShow(Sender: TObject; var Done: Boolean);
  2. var
  3.   Start: Double;
  4. begin
  5.   Start := GetTickCount64;
  6.   Application.OnIdle := FOldOnIdle;                 // Restore catched OnIdle.
  7.   Label1.Caption:=Format('Sleep: %.3f', [GetTickCount64-Start]);
  8.   Application.ProcessMessages;
  9.  
  10.   Start:=GetTickCount64;
  11.   Sleep(3000);  // loading data
  12.   Memo1.Lines.Add(Format('Waited %f ticks', [GetTickCount64-Start]));
  13.   Memo1.ScrollBy(0, Memo1.Lines.Count);
  14.   Label1.Caption:=Format('Slept(%f)', [GetTickCount64-Start]);
  15.   Done := True;
  16. end;
  17.  
  18. procedure TForm1.FormShow(Sender: TObject);
  19. begin
  20.   FOldOnIdle := Application.OnIdle; // Save current OnIdle.
  21.   Application.OnIdle:=@AfterShow;
  22. end;
  23.  
Windows 11 UTF8-64 - Lazarus 4.8-64 - FPC 3.2.2

cdbc

  • Hero Member
  • *****
  • Posts: 2931
    • http://www.cdbc.dk
Re: Is it good idea TForm to have AfterShow event
« Reply #6 on: December 21, 2025, 07:35:06 pm »
Hi
from/@ zeljko:
Quote
not sure that PostMessage works with all widgetsets.

I would think so, as it's implemented in the LCL, so if the underlying widgetset, doesn't directly support it, the developer has to provide an implementation for it or similar...
I've just played around with fpGUI 1.5.0 and the first thing I checked was comms with multithreading and 'fpgPostMessage();' as it happens to be called in fpGUI... It works great.  8-)
I think only winders is natively born with that exact system  %)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018