I have been using TForm
's OnActivate
event to give me the opportunity to show a dialog box as soon as my app has started. I want the main form to already be loaded & visible. What's a good way to do this?
I have found that OnActivate
works fine unless the forms WindowState
is wsMaximized
.
in the past I've accomplished what I want in various ways but I expect there is a better way.
Here's what worked for me:
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnIdle:=OnIdle;
end;
procedure TForm1.OnIdle(Sender: TObject; var Done: Boolean);
begin
Application.OnIdle:=nil;
form2:=TForm2.Create(Application);
form2.ShowModal;
end;
Is there a better way?
In the MainForm's OnShow
event, you can do one of the following to show the dialog box after a delay that allows the MainForm to finish fully showing itself first:
PostMessage()
a custom window message to yourself.TThread.CreateAnonymousThread()
or TTask
to call TThread.Queue()
.TThread.ForceQueue()
(10.2 Tokyo and later only).