Specifying Default Values

From RAD Studio
Jump to: navigation, search

Go Up to Storing and Loading Properties


Delphi components save their property values only if those values differ from the defaults. If you do not specify otherwise, Delphi assumes a property has no default value, meaning the component always stores the property, whatever its value.

To specify a default value for a property, add the default directive and the new default value to the end of the property declaration.

You can also specify a default value when re-declaring a property. In fact, one reason to re-declare a property is to designate a different default value.

__property Alignment = {default=taCenter};

Note: Specifying the default value does not automatically assign that value to the property on creation of the object. You must make sure that the component's constructor assigns the necessary value. A property whose value is not set by a component's constructor assumes a zero value- that is, whatever value the property assumes when its storage memory is set to 0. Thus numeric values default to 0, Boolean values to False, pointers to nil, and so on. If there is any doubt, assign a value in the constructor method.

See Also