That's perfectly fine with me. I just think it's a waste of time, that's all. After all, after you've found that it's not nil, you'll have to call FreeAndNil() that will do this test again for you. And, in most instances, you'll probably find that Assigned() evaluates to true anyway (OK, so I realise this depends on the code, but in my experience this is most of the case), and hence doubling up on your efforts. IMHO, readability is only impaired if you don't know what Free() and FreeAndNil() does.
-Andreas -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Guy Brown Sent: Monday, 3 March 2003 10:19 To: Multiple recipients of list delphi Subject: RE: [DUG]: Freeing Stringlists. I stand corrected. However I still think that it is better practise to explicitly test Assigned() first for the reasons that David mentioned. Guy -----Original Message----- From: Andreas Toth [mailto:[EMAIL PROTECTED] And what do you think Free() does -- checks to see if it is nil or not, just like you are doing with Assigned(). -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Guy Brown Nope, FreeAndNil() frees the object and then nil's the reference you passed to it so that any other clean up code that uses Assigned() to test the same reference won't free the object a second time. Guy ------------ >From sysutils: procedure FreeAndNil(var Obj); var P: TObject; begin P := TObject(Obj); TObject(Obj) := nil; // clear the reference before destroying the object P.Free; end; -------------- -----Original Message----- From: Andreas Toth [mailto:[EMAIL PROTECTED] There's no need to use Assigned() since FreeAndNil() performs a similar test... -Andreas -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Peter Speden Try If Assigned (includelist) then FreeAndNil (includelist); Etc Or If includelist <> nil then FreeAndNil (includelist); They are not freed elsewhere are they. Peter Speden --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/ --------------------------------------------------------------------------- New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED] Website: http://www.delphi.org.nz To UnSub, send email to: [EMAIL PROTECTED] with body of "unsubscribe delphi" Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
