开发者

Stored keyword in Delphi

Delphi allows a stored keyword when defining properties as follows:

property Fields开发者_JAVA百科: TIndexDefs read FFields write SetFields stored FieldsStored;

What is the purpose of the keyword and what does it do?


From my Delphi 7 help file:

The optional stored, default, and nodefault directives are called storage specifiers. They have no effect on program behavior, but control whether or not to save the values of published properties in form files.

The stored directive must be followed by True, False, the name of a Boolean field, or the name of a parameterless method that returns a Boolean value. For example,

property Name: TComponentName read FName write SetName stored False;

If a property has no stored directive, it is treated as if stored True were specified.

It controls whether or not to store a property relating to a component in the .DFM file for the form.


This keyword determines if a property value should be saved in a form file; it is true by default. It can be useful to avoid, for example, saving big chunks of binary information in your .dfm file (for example, an image component that must read its contents at runtime only.)


The stored directive takes a Boolean value: a method that returns a Boolean result, a Boolean-type field reference, or a constant expression of Boolean type. The property’s RTTI records the field offset, method reference, or constant value, and Delphi’s IDE uses this information to decide whether to omit the property from the .dfm file.

The IDE calls the method, checks the field’s value, or uses the constant Boolean value, and if the value is False, the property is not saved to the .dfm file. If the stored value is True, the default behavior occurs, namely, that the property is stored if its value is different from the default value.

Tips and Tricks

  • The stored directive is often misunderstood. Setting stored to True does not force Delphi to store the property value in the .dfm file. True is the default value of the stored directive. Instead, all you can do is omit the property from the .dfm file by setting stored to False.

  • You can use stored with properties at any access level, but it has meaning only for published properties.

  • If you use a method name, the method can be static or virtual, but not dynamic or a message handler.

  • A field reference can be a field name, a record member, or an array element with a constant index. The field reference must have a Boolean type.

Reference: https://www.oreilly.com/library/view/delphi-in-a/1565926595/re307.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜