From Appmethod Libraries
Jump to: navigation, search

Object Pascal

procedure FreeAndNilProperties(AObject: TObject);


extern DELPHI_PACKAGE void __fastcall FreeAndNilProperties(System::TObject* AObject);


Type Visibility Source Unit Parent
System.TypInfo System.TypInfo


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

Call FreeAndNilProperties from a destructor to free all internally created objects and set the corresponding property values to nil (Object Pascal) 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 (Object Pascal) 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 Object Pascal 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 (Object Pascal) or NULL (C++) before calling FreeAndNilProperties.

See Also