Thanks all for your comments on and insights into this subject (looks like I 
started again that debate I said I'd seen in the past!).  I think I'm getting 
my head around this now:
if you close a form using OnClose with caFree, Release gets called (see Doug 
Hale's code quotation) which posts a CM_RELEASE message to the form allowing 
all other messages to be processed before this one (see Theo's explanation), 
and finally Delphi's message handler for CM_RELEASE, TCustomForm.CMRelease, 
calls Free, in which case it would be prudent to set the existing pointer to 
nil.  If I've misunderstood, then I'm probably just too dumb ever to understand 
it - I should forget the technical and just take the empirical approach!   
Thanks again for all the input.

Steve 

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED]
Behalf Of David Smith
Sent: 18 November 2008 18:27
To: [email protected]
Subject: RE: [delphi-en] Multiple instances of form


   I always presumed the reason for that was because a pointer to the global 
form variable is left "dangling" and you will have no way to know if the app is 
still in memory or not (not to mention causing a GPF if you inadvertantly refer 
to after freeing). After freeing, you always want to set the form variable to 
nil so the "If Assigned" check will work. 
I.E.
Form1.free;
Form1 := nil;

Dave

--- On Tue, 11/18/08, Wilson, Stephen <[EMAIL PROTECTED]> wrote:
From: Wilson, Stephen <[EMAIL PROTECTED]>
Subject: RE: [delphi-en] Multiple instances of form
To: [email protected]
Date: Tuesday, November 18, 2008, 8:52 AM



***************************************************************************
This e-mail and any files transmitted with it are confidential. If you are not 
the intended recipient, any reading, printing, storage, disclosure, copying or 
any other action taken in respect of this e-mail is prohibited and may be 
unlawful. If you are not the intended recipient, please notify the sender 
immediately by using the reply function and then permanently delete what you 
have received.
Content of emails received by this Trust will be subject to disclosure under 
the Freedom of Information Act 2000, subject to the specified exemptions, 
including the Data Protection Act 1998 and Caldicott Guardian principles.
This footnote also confirms that, unless otherwise stated, this email message 
has been swept by Sophos Anti-virus for the presence of computer viruses.
***************************************************************************

Reply via email to