Solved

FormDestroy being called twice?

Posted on 2004-03-24
8
543 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
When I am typing into a TEdit last word repeats 7 162
Delphi 2 77
Press three keys together and trigger a function 3 67
Multi-layered image in FireMonkey 9 68
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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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