6.7.6 Storage information

The compiler offers two specifiers to control whether a property is streamed using a streaming mechanism, such as the one implemented in the classes unit. These specifiers write extra information to the generated RTTI, which is later used in the streaming system:

  1. The stored specifier.
  2. The default specifier and its counterpart nodefault.

These two specifiers are both evaluated to decide whether a property must be streamed.

The argument to the stored specifier should be either a boolean constant, a boolean field of the class, or a parameterless function which returns a boolean result. If the argument of the stored specifier evaluates to False, the property will not be streamed.

Remark Absence of a stored specifier is equivalent to stored True.

If the evaluation of Stored resulted in True, the default for a property is considered:

The default specifier can be specified for ordinal types and sets. Properties that have as value this default value, will not be written to the stream by the streaming system, even if Stored is True. The default value is stored in the RTTI that is generated for the class.

String, floating-point and pointer properties have implicit default value of empty string, 0 or nil, respectively. Ordinal and set properties have no implicit default value.

The nodefault specifier must be used to indicate that a property has no default value. The effect is that the value of this property is always written to the stream when streaming the property, if stored is True.

Remark

  1. When the class is instantiated, the default value is not automatically applied to the property, it is the responsibility of the programmer to do this in the constructor of the class.
  2. The value -2147483648 cannot be used as a default value, as it is used internally to denote nodefault.
  3. It is not possible to specify a default for array properties.
  4. It is not possible to specify the Stored directive for array properties.
  5. All storage specifiers can be overridden in descendent classes.
    property Test stored False;

  6. The nodefault specifier can be used to override the implicit default specifier of string, floating-point and pointer properties.
  7. The streaming mechanism described here is the one implemented in the classes unit of the RTL. Other streaming mechanisms can be implemented, and they can use the RTTI information in a different way.