Name
Default Directive
Syntax
propertyDeclaration
; default; propertyDeclaration
defaultOrdinal 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
default
directive, Delphi assumes you meannodefault
and 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 ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.