Start Free Trial
Come for the solution, stay for everything else.
Start Free Trial
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?
8/22/2022 - Mon
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.
I actually tried this and did not alleviate the problem.
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
As mentioned in the initial question, it is never called implicitly.
And it only appears under OnFormDestroy in the DFM text.
ASKER CERTIFIED SOLUTION
Log in or sign up to see answer
Become an EE member today
7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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.
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.
to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Yes, it is the main form, and it is only instantiated once.
Plans and Pricing
Certified Expert Program
© 1996-2022 Experts Exchange, LLC. All rights reserved. Covered by US Patent