[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

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.

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