[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

FormResize Event

Posted on 2001-07-15
15
Medium Priority
?
353 Views
Last Modified: 2010-04-06
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.

  Thanks, David.
0
Comment
Question by:King_David
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +5
15 Comments
 
LVL 2

Expert Comment

by:bugroger
ID: 6283217
Can you post your code for FormResize and FormDestroy?

May be you call something in your Destroy-Event that will
be change the size of your form?
0
 
LVL 1

Author Comment

by:King_David
ID: 6283224
Even if I comment all the code in the FormDestroy it
still happens.
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6283227
And if you comment all the code in FormResize?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Expert Comment

by:nnbbb09
ID: 6283234

It's difficult to see what the problem is without a listing of your unit.

However there is a quick way to prevent your FormResize firing after the form has started to destroy itself. Just make this the first line of your FormResize event handler.

If csDestroying in ComponentState then
  exit;

However this just avoids the problem rather than actually fixing it.

Jo
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6283238
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...

Regards, Madshi.
0
 
LVL 1

Author Comment

by:King_David
ID: 6283244
If I add OnResize := Nil; as the first line of my
FormDetroy Event, the FormResize is not triggered but
my application end with runtime error 216.

These solutions are work-arounds, I would like to solve
this bug.
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6283250
It's also an access violation !

if you post your code if would be much easier.
0
 
LVL 3

Expert Comment

by:nnbbb09
ID: 6283254

Out of interest, did you try my solution?
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6283267
>> These solutions are work-arounds, I would like to solve
this bug.

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 "$").
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 6283335
If you destroy the form with FormX.Free, change it to FormX.Release.
0
 
LVL 2

Expert Comment

by:ivobauer
ID: 6284941
Hi all!

This is just my opinion. Maybe, when form is being freed,  you access the components which no longer exists in OnResize event handler. Try to encapsulate your code in TForm.OnResize event handler like:

procedure TForm1.FormResize(...);
begin]
  if not (csDestroying in ComponentState) then
  begin
    // put here your original code
  end;
end;

Best regards, Ivo.
0
 
LVL 3

Expert Comment

by:rondi
ID: 6285235
begin
  if Application.Terminated then exit;
  ...
  ...
  ...
0
 
LVL 1

Accepted Solution

by:
alx512 earned 600 total points
ID: 6294347
The FormResize Event is triggered after FormDestroy Event
becouse the WM_SIZE message processed. I think it called by DefaultWindowHandler;

In Controls.pas you can see this code:

procedure TWinControl.WMSize(var Message: TWMSize);
begin
  UpdateBounds;
  inherited;
  Realign;
  if not (csLoading in ComponentState) then Resize;
end;

I think what this code must check also csDestroyng status, before call of Resize proc.

The problem that you encountered is not in FormResize event, check your other code.
0
 
LVL 1

Author Comment

by:King_David
ID: 6298487
alx512, you have a point.

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.

0
 
LVL 1

Author Comment

by:King_David
ID: 6298869
I'm giving the points to alx but I thank all you for your
help.

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question