Hi Ross, I have mentioned in that previous email about the issue related to should call free or release. Which is the proper way? I think should call release method.
If that is true, the code should be changed to this. aAutoObject.release; aAutoObject := nil; But release method does not check nil pointer, thus that code won't be correct. Regards Leigh -----Original Message----- From: Ross Levis [mailto:[EMAIL PROTECTED] Sent: Wednesday, 23 November 2005 2:11 p.m. To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: Re: [DUG] FreeAndNil for TAutoObject in Delphi 5 Well, you could do away with the Assigned() since Free will be ignored if the object is already nil, so in 2 lines of code... aAutoObject.Free; aAutoObject := nil; Ross. ----- Original Message ----- From: "Leigh Wanstead" <[EMAIL PROTECTED]> To: "Rohit Gupta" <[EMAIL PROTECTED]>; <[email protected]> Sent: Wednesday, November 23, 2005 1:35 PM Subject: RE: [DUG] FreeAndNil for TAutoObject in Delphi 5 Hi Rohit, That is five lines of code. The demo code I show was one line code. Regards Leigh -----Original Message----- From: Rohit Gupta [mailto:[EMAIL PROTECTED] Sent: Wednesday, 23 November 2005 1:36 p.m. To: [EMAIL PROTECTED]; NZ Borland Developers Group - Delphi List Subject: Re: [DUG] FreeAndNil for TAutoObject in Delphi 5 Leigh, whats worng with if assigned (aAutoObject) then begin aAutoObject.Free; aAutoObject := nil; end; Leigh Wanstead wrote: >Hello everyone, > >I plan to write a method similar to Delphi7 freeandnil procedure, but >for >TAutoObject in Delphi 5 version. > >Here is the prototype code. > >procedure STTAutoObjectRelease(var aAutoObject: TAutoObject); >var > varAutoObject: TAutoObject; >begin > varAutoObject := aAutoObject; > if varAutoObject = nil then > begin > Exit; > end; > > TObject(aAutoObject) := nil; // clear the reference before > destroying the >object > varAutoObject.release; >end; > >But the issue is I worried about TAutoObject will be like interface, >every >time pass between method, auto increment, decrement reference counting. That >make this method to complex to decide. > >The normal way to do is like here. > if assigned(fAutoObject) then > begin > fAutoObject.Release; > end; > >But that is three lines code. > >Here is what I proposed to do. > >STTAutoObjectRelease(fAutoObject); > >TIA > >Regards >Leigh >http://www.salenz.com > > >_______________________________________________ >Delphi mailing list >[email protected] >http://ns3.123.co.nz/mailman/listinfo/delphi > > > > > _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi _______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
