[Lazarus] Difference between FreeThenNil and FreeAndNil

Luiz Americo Pereira Camara luizmed at oi.com.br
Wed Apr 27 04:30:54 CEST 2011


After reading http://bugs.freepascal.org/view.php?id=19238 i wondered 
what's the reason to FreeThenNil procedure found in LCLProc.

What's the advantage over SysUtils FreeAndNil ?

procedure FreeThenNil(var obj);
begin
   if Pointer(obj) <> nil then
   begin
     TObject(obj).Free;
     Pointer(obj) := nil;
   end;
end;


     procedure FreeAndNil(var obj);
       var
         temp: tobject;
       begin
         temp:=tobject(obj);
         pointer(obj):=nil;
         temp.free;
       end;

Luiz






More information about the Lazarus mailing list