[Lazarus] Different "default" value for a property in derivedclass

Michael Van Canneyt michael at freepascal.org
Sun Apr 7 00:18:18 CEST 2013



On Sat, 6 Apr 2013, Hans-Peter Diettrich wrote:

> Jether (yahoo) schrieb:
>> This doesn't make any sense to me, TB is descendent of TA, TB should never 
>> affect the behavior of it's ancestror TA.
>
> Properties are evaluated at compile time. When an object reference is known 
> to be of type TB, the compiler uses the getter/setter methods of TB.
>
> Nonetheless I don't understand what initialized properties in non-component 
> classes are good for, together with the observed behaviour  of default 
> values. Can somebody point me to the according documentation?

Default values are simply stored in RTTI. 
RTTI is generated for all TPersistence descendents such as TStrings or TCollectionItem.
(or as Sven pointed out, any descendent of a class compiled in {$M+})

They have no other purpose than inform a streaming implementation what the 
default value is expected to be after the constructor was called.

There is no guarantee from the compiler that this will actually be the case. 
It depends on the constructor of the class.

This can be used to:

* omit values when streaming the component. This is what is currently done.

* One could imagine an implementation in a class that retrieves all default values and
   initializes them "automatically". However, this can have side-effects if there is a
   property setter, so it is not implemented in TComponent.

All this is documented in the language reference manual:

http://www.freepascal.org/docs-html/ref/refsu37.html

Michael.




More information about the Lazarus mailing list