[Lazarus-es] Duda sobre funcion free

Jose Antonio Cuello josea en artextrading.com
Mar Jul 28 13:48:02 CEST 2009


Joer, había mirado el código fuente pero no lo ví claro. Está claro que 
estaba dormido ... :-[
Gracias, ya lo ví ... lo dice los mismos nombres de función. 
"FreeAndNil" y "FreeThenNil" ... :-D :-D
> Message: 1
> Date: Tue, 28 Jul 2009 11:16:31 +0200
> From: JoshyFun <joshyfun en gmail.com>
> Subject: Re: [Lazarus-es] Duda sobre funcion free
> To: Spanish version of Lazarus List
> 	<lazarus-es en lists.lazarus.freepascal.org>
> Message-ID: <14610477244.20090728111631 en gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hello Jose,
>
> Tuesday, July 28, 2009, 9:38:05 AM, you wrote:
>
> JAC> Hola, alguien me puede indicar si es mejor usar "FreeAndNil" o 
> JAC> "FreeThenNil".
> JAC> Gracias y un saludo.
>
> Compara los códigos:
>
> FreeAndNIL:
>
> procedure FreeAndNil(var obj);
>   var
>     temp: tobject;
>   begin
>     temp:=tobject(obj);
>     pointer(obj):=nil;
>     temp.free;
>   end;
>
> FreeThenNIL:
>
> procedure FreeThenNil(var AnObject: TObject);
> begin
>   if AnObject<>nil then begin
>     AnObject.Free;
>     AnObject:=nil;
>   end;
> end;
>
> Y creo que el "help" del fpc aclara la duda:
>
> "FreeAndNil will free the object in Obj and will set the reference in
> Obj to Nil. The reference is set to Nil first, so if an exception
> occurs in the destructor of the object, the reference will be Nil
> anyway."
>
>   





More information about the Lazarus-es mailing list