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 nodefault directive 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, so nodefault is almost the same as default -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 the nodefault marker value.)

  • The nodefault directive is optional. If you omit it, Delphi assumes nodefault. You should use nodefault in 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

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.