[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

FormDestroy being called twice?

Posted on 2004-03-24
8
Medium Priority
?
559 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
Independent Software Vendors: 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 150 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
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