[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

FormDestroy being called twice?

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
djdj
Asked:
djdj
  • 4
  • 4
1 Solution
 
RobnCommented:
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
 
djdjAuthor Commented:
I actually tried this and did not alleviate the problem.
0
 
RobnCommented:
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
Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

 
djdjAuthor Commented:
As mentioned in the initial question, it is never called implicitly.

And it only appears under OnFormDestroy in the DFM text.
0
 
RobnCommented:
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
 
djdjAuthor Commented:
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
 
RobnCommented:
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
 
djdjAuthor Commented:
Yes, it is the main form, and it is only instantiated once.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now