RAD Studio
ContentsIndex
PreviousUpNext
Specifying Default Values

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.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!