How can I be sure that in some point of my VCL application lifetime the Application.MainForm is valid so I could post a message to it (from a MadExcept ExceptionHandler).
This could be at any point (in the context of any thread) in my application (also initialization, finalization etc...)
I was thinking:
if Assigned(Application)
and (not Application.Terminated)
and Assigned(Application.MainForm)
and Application.MainForm.HandleAllocated then
begin
PostMessage(Application.MainForm.Handle, MyMessage, 0, 0);
end;
Is this correct?
Make some global variable flag
= falseat the beginning.Make your mainform turn it to
true.Check that flag to see if main form was already initialised or not yet.
You can make it from such places as mainform's
OnActivateevent or overriddenTMainForm.LoadedmethodSimilarly when your application would be terminating and the mainform would get hidden (and later even destroyed) - you would reset the flag back to
false