Yes, but Free itself checks whether the object reference is nil before
proceeding.

Having said that I tend to still check for Assigned before Freeing if it's
an object that could quite legitimately be nil. I do it mainly for
readability and to indicate that the object may be nil, rather than because
I have to.

David

--------------
>From system.pas:

procedure TObject.Free;
asm
        TEST    EAX,EAX
        JE      @@exit
        MOV     ECX,[EAX]
        MOV     DL,1
        CALL    dword ptr [ECX].vmtDestroy
@@exit:
end;

;-)

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Behalf Of Guy Brown
> Sent: Monday, 3 March 2003 9:42 AM
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: Freeing Stringlists.
>
>
> 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/

Reply via email to