Name
Nodefault Directive
Syntax
property Declaration nodefault;Description
The nodefault directory tells Delphi that the
property does not have a default value and that the
.dfm file should always contain the property
value.
Tips and Tricks
Only ordinal-type properties can have default values, so the
nodefaultdirective has meaning only for these properties. String, floating-point, class,Variant,Int64, and interface-type properties have a hardcoded default value of “zero” (empty string,nil,Unassigned, etc.).Delphi stores the smallest integer as the marker for
nodefault, sonodefaultis almost the same asdefault-2147483648. (“Almost” because properties of enumerated, character, or set type cannot have an integer constant as a default value, which is one reason Delphi uses the most negative integer as thenodefaultmarker value.)The
nodefaultdirective is optional. If you omit it, Delphi assumesnodefault. You should usenodefaultin your property declarations as a reminder to the person who must read and maintain your code that the property has no default value.Delphi always constructs new objects with zero for all fields. If you want to use zero as the default value for a property, you must explicitly declare zero as the default value in the property declaration. You do not need to do anything special in the constructor.
Example
property Color nodefault; property Area: Integer read fArea write SetArea nodefault;
See Also
| Default Directive, Property Keyword, Stored Directive |
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