RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TypInfo.FreeAndNilProperties Function

Frees any property values that are objects and sets their value to nil (Delphi) or NULL (C++).

Pascal
procedure FreeAndNilProperties(AObject: TObject);
C++
FreeAndNilProperties(TObject * AObject);

TypInfo

Call FreeAndNilProperties from a destructor to free all internally created objects and set the corresponding property values to nil (Delphi) or NULL (C++). FreeAndNilProperties searches the properties of AObject, identifying any that are objects. It frees those objects, and sets the corresponding property to nil (Delphi) or NULL (C++). 

. By default, all persistent objects (TPersistent and descendants) are compiled with RTTI. Other TObject descendants can be compiled with RTTI by using the $M+ compiler switch in Delphi or the __declspec(delphirtti) directive in C++.

Warning: Calling FreeAndNilProperties frees all object properties, which may lead to unintended results. FreeAndNilProperties can't distinguish between objects that were created by AObject (and typically stored in a class member) from objects that are created independently and which should not be freed with AObject. To avoid unintentionally freeing independently-created objects, set properties that refer to external objects to nil (Delphi) or NULL (C++) before calling FreeAndNilProperties.
 

 

FreeAndNil

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!