Table of Contents

RegisterCustomProperty Method

Registers a custom (virtual) property for the specified class.

Remarks

You can use this procedure to create a new custom (virtual) property for a specified class. When a list of properties is built for a specific object, all available properties for the object are retrieved using RTTI and added to the property list, and it also includes all custom properties registered for the object class. For example, you can create a new custom property named "MyProp" for the class TEdit. This way, whenever a list of properties for an object is of class TEdit is about to be built, a property named "MyProp" will appear as if it was a real property of the TEdit class. You can then specify custom procedures to read and and write the MyProp value, simulating the getter and the setter of that property.

Syntax

Unit: PropertyList

procedure RegisterCustomProperty(AInstanceType: TClass; APropName: string; APropType: PTypeInfo; ADescendants: Boolean; AGetProc: TGetPropertyValue; ASetProc: TSetPropertyValue);

Parameters

<-> Parameter Type Description
AInstanceType TClass The class for which the custom property will be registered.
APropName string The name of the new property.
APropType PTypeInfo The PTypeInfo information about the property. This will hold the actual data type of the property.
ADescendants Boolean If true, the new property will appear in objects of the specified class, and also objects descending of the class. If false, only objects of the specified class will have it.
For example, if the property was registered for a TWinControl, then a TEdit or TButton object will also display the custom property if ADescendants is true. If it is false, the property will only appear for TWinControl objects, and TEdit and TButton classes will not show the custom property.
AGetProc TGetPropertyValue A reference to a procedure that will implement the property Getter.
ASetProc TSetPropertyValue A reference to a procedure that will implement the property Setter.