[fpc-pascal] FPC class syntax was extended to support delphi code

Marc Weustink marc at dommelstein.net
Fri Jan 15 00:19:14 CET 2010


Paul Ishenin wrote:
> David Emerson wrote:
>> d. What happens with inheritance?
>>
>> d.1. wrt class constants and class vars-- are there separate 
>> "instances" (for lack of a better word) of these, one instance for 
>> each descendant? Or is the class var/const only stored once for the 
>> ancestor that declares it, and all descendants share that?
>>   
> Class vars (static class fields) are stored only once for the class 
> which declares them and all descendants share that.
> 
> Example:
> TSomeClass = class
> class var Value: Integer;
> end;
> 
> TDescendant = class(TSomeClass);
> begin
>  TSomeClass.Value := 1;
>  TDescendant.Value := 2;
>  WriteLn(TSomeClass.Value); // this must output 2
> end;
> 
> Class static field is not a new feature. But now you can declare them 
> using 'class var' section after methods or 'type'/'const' section.

Can we have a virtual version too like described here
http://hallvards.blogspot.com/2007/05/hack17-virtual-class-variables-part-i.html


Marc




More information about the fpc-pascal mailing list