Name
Default Directive
Syntax
propertyDeclaration; default; propertyDeclarationdefaultOrdinal constant;
Description
The
default directive has two uses in property
declarations:
To make an array property the class’s default property
To supply a default value for an ordinal-type property
A class can declare one array property as the default property for
the class. The default property lets you refer to an object reference
as an array without mentioning the property name. For example,
TList declares the Items
property as its default array property. If List is
a variable of type TList, you can refer to a list
element as List[Index], which is a shorthand for
List.Items[Index]. A class can have only one
default property. Derived classes can define a different default
property from that of an ancestor class.
An ordinal-type property (integer, enumeration, set, or character
type) can list a default value. The default value has no effect on
the property’s initial value. Instead, the default value is
stored in the class’s RTTI, and Delphi’s design-time and
runtime environments use the default value to reduce the size of a
.dfm file or resource. Non-ordinal properties
(e.g., floating-point, string, class) always use zero (empty string,
nil, etc.) as the default value.
Tips and Tricks
If you do not specify a
defaultdirective, Delphi assumes you meannodefaultand stores the smallest integer (-2,147,483,648) as the property’s default value. A side effect is that you cannot use the smallest integer ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access