FormResize Event

I've FormResize and FormDestroy Events on my Main Form.
Strangly, when closing the form the FormResize Event
is triggered after my FormDestroy Event.
What could be the cause of this behaviour?
Sometimes, not allways, the application ends with an
access violation on exiting the FormResize.

Another quick fix (without knowing the reason why FormResize is triggered) would be to set the OnResize handler in your OnDestroy handler to nil:

procedure TForm1.FormDestroy(...);
begin
OnResize := nil;
[...]
end;

If you want to know who triggers the FormResize event, you should go through all your code step by step in the debugger, starting at FormDestroy. Maybe one component on your form does something weird when being destroyed. Who knows?
Maybe it also helps you to set a breakpoint to FormResize, and if you get there after FormDestroy, look at the callstack, it maybe also shows you who is responsible for triggering the FormResize event...

Then you're a real programmer. In that case reread the last two paragraphs of my previous comment:

"If you want to know who triggers the FormResize event, you should go through all your code step by step
in the debugger, starting at FormDestroy. Maybe one component on your form does something weird when
being destroyed. Who knows?
Maybe it also helps you to set a breakpoint to FormResize, and if you get there after FormDestroy, look
at the callstack, it maybe also shows you who is responsible for triggering the FormResize event..."

I can add a third possibility to find the real bug: Where does the access violation occur (runtime error 216 = access violation), when you do that "OnResize := nil"? This might exactly be the guilty code location. Use "Find runtime error" to find the source line. (This function works only if the process is running, so press F7 once to get into the debugger, then click "Find runtime error", then give in the address with a leading "$").

Here is what I found so far:
Look at procedure TCustomForm.WMDestroy
pay attention to the line "if (FMenu <> nil)..."
If I set in my FormDestroy
MainMenu.Free;
MainMenu := Nil;
then the event is not triggered and I'm happy.

the solution:
My form has many components with their Align set.
When the form is detroyed, the MainMenu gets destoyed
and a lot of activities are going on to resize
the form.
And the solution is: in FormCloseQuery I destroy
the MainMenu and set it to nil, this triggers the
FormResize event and when the FormDestroy is triggered
FormResize remains calm.

Regards, David.

0

Featured Post

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.