__alex
asked on
Destroying form while in event handler
I've got a main form and a subform. My main form is responsible for creating and destroying the subform. In an event handler (a ButtonClick) of the subform there's a loop like
for i := 0 to whatever do
DoStuff;
Application.ProcessMessage s; // To refresh some controls
DoMoreStuff; // (*)
end;
I want the user to be able to destroy the subfrom via main form while the subform is in that loop. After the destructor has finished the program continues at (*) which leads to a crash (because the resources accessed in DoMoreStuff are gone).
I thought about not to close the subform in the main form but start another thread that monitors the loop and closes the subform from this thread but that's breaking a fly on the wheel...
Any hints? Thanks in advance!
for i := 0 to whatever do
DoStuff;
Application.ProcessMessage
DoMoreStuff; // (*)
end;
I want the user to be able to destroy the subfrom via main form while the subform is in that loop. After the destructor has finished the program continues at (*) which leads to a crash (because the resources accessed in DoMoreStuff are gone).
I thought about not to close the subform in the main form but start another thread that monitors the loop and closes the subform from this thread but that's breaking a fly on the wheel...
Any hints? Thanks in advance!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BTW: Closing a form is not destroying it ;-)
Closing a form will lead to it being destroyed, unless you set Action to caNone at the OnClose =p
you can also optionally, call Release, when you receive the message
you can also optionally, call Release, when you receive the message
ASKER
Default Action is caHide (for non MDI childs)
ASKER