Solved

FormDestroy being called twice?

Posted on 2004-03-24
8
548 Views
Last Modified: 2010-04-05
I have an application where FormDestroy is being called twice and I'm not sure why.

I don't reference the method directly anywhere in my code, but yet the method is being called twice (sometimes!).

Anyone know why, or how to prevent it?
0
Comment
Question by:djdj
[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
  • 4
8 Comments
 
LVL 2

Expert Comment

by:Robn
ID: 10669414
This is very strange and I can't say I have ever heard of this before. However, you can easily solve this by placing this line at the top of the FormDestroy event.

OnDestroy := nil;

This will stop any subsequest event driven calls to the method.

Regards,
Rob
0
 
LVL 2

Author Comment

by:djdj
ID: 10670133
I actually tried this and did not alleviate the problem.
0
 
LVL 2

Expert Comment

by:Robn
ID: 10670169
Search in your code for places where you implicitly call the method. Also, open the DFM and look for other places where this event is attached. Something is calling it and it is not the form itself.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:djdj
ID: 10670260
As mentioned in the initial question, it is never called implicitly.

And it only appears under OnFormDestroy in the DFM text.
0
 
LVL 2

Accepted Solution

by:
Robn earned 50 total points
ID: 10670293
In that case, I can only assume a memory overwrite. Another way to handle it would be this

TMyForm = class(TForm)
  procedure FormDestroy(Sender: TObject);
  private
    FDestroyCalled: Boolean;
end;

procedure TMyForm.FormDestroy(Sender: TObject);
begin
  if FDestroyCalled then Exit;
  FDestroyCalled := True;
  .......
end;

This may get you running again until you can find what exactly is causing the problem.
0
 
LVL 2

Author Comment

by:djdj
ID: 10670472
I'm doing something similar now... but instead of using a variable that is a property of the form object i'm using a CONST that's part of the unit instead (that way it is still valid after the form is destroyed).

I hate using workarounds, and was hoping that this was possibly a known bug in Delphi so I know its not something I'm doing wrong.
0
 
LVL 2

Expert Comment

by:Robn
ID: 10670524
If this is the main form, you'll be alright using the constant. However, if you have the ability to have 2 or more of these forms open, you will loose the garbage cleanup on subsequent forms (as I'm sure you are aware of).

Thanks for the points.

Regards,
Rob
0
 
LVL 2

Author Comment

by:djdj
ID: 10670557
Yes, it is the main form, and it is only instantiated once.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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