6.7 Class properties

Class properties are very much like global property definitions. They are associated with the class, not with an instance of the class.

A consequence of this is that the storage for the property value must be a class var, not a regular field or variable of the class: normal fields or variables are stored in an instance of the class.

Class properties can have a getter and setter method like regular properties, but these must be static methods of the class.

That means that the following contains a valid class property definition:

TA = Class(TObject)  
  class var myprivatea : integer;  
  class Function GetB : Integer;  static;  
  class Procedure SetA(AValue : Integer); static;  
  class Procedure SetB(AValue : Integer); static;  
  Class property MyA : Integer Read MyPrivateA Write SetA;  
  Class property MyA : Integer Read GetB Write SetB;  

The reason for the requirement is that a class property is associated to the particular class in which it is defined, but not to descendent classes. Since class methods can be virtual, this would allow descendent classes to override the method, making them unsuitable for class property access.