Actually just write an onClose event for the main form and set the CloseAction var parameter to caFree. That will free the form and since the application is registered to be called when the mainform is destroyed it will set the mainform property to nill.
I modified my test application and applied your tip, but it doesn't work. I generated
OnClose events for all forms and assigned
caFree to
CloseAction, but the second call to the
Run method ends immediately and
LoginForm appears again. So the login form is not closed and must be freed by
Application.MainForm.Free.
Thanks for the code snippet. IMO something like this should be implemented in
TApplication class.