[fpc-devel] No default property value allowed for double type?

Bram Kuijvenhoven kuifwaremailinglists at xs4all.nl
Tue May 17 10:06:45 CEST 2005


Peter Vreman wrote:
> I don't know the reason why single is allowed. Delphi doesn't allow
> default values for single or double.

I looked it up in the Delphi documentation (I should have done that before) and found out the default directive even has a different meaning from what I thought :)

I thought it would set a default value for that property, but that isn't true; you still need to do that in the constructor. I will provide a small explanation for reference.

default is (for non-array properties) a so called storage specifier. Published component properties with a default value are only written to a form file during saving of the component when their value differs from the specified default value. The Delphi documentation says that one can only specify a default value for properties of
- an ordinal type or
- a set type with the lower and upper bound of the ordinal values of the sets base type in the range 0..31
Reals, strings, and pointers have the implicit default values 0, '' and nil respectively. Furthermore, there exists an stored directive which controls whether the property is written at all and a nodefault specifier which simply indicates the absence of a default value. By default a property has no default and is stored. The stored directive has a boolean constant, a boolean field, or a parameterless method returning a boolean as parameter.

Note that the default directive for array properties indicates it is the default (array) property for that class (and is parameterless), allowing syntaxis like

type
  TList = class
    ...
    property Items[i:integer]:pointer read GetItem write SetItem default;
    ...
  end;
...
var
  MyList:TList;
...
  MyList[i]

as explained in the FPC docs.

The storage specifiers are not explained in the FPC reference manual as far as I know, though they are in the syntaxis diagram of course.

And somehow FPC allows default values for singles.

Bye,

Bram




More information about the fpc-devel mailing list