extended class syntax

From Free Pascal wiki
Revision as of 16:45, 13 January 2010 by Paul Ishenin (talk | contribs) (New page: <delphi> type TSomeClass = class private type TSomeType = type integer; // an internal type class var FSomeClassVar: TSomeType; // class variable belongs to a...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

<delphi> type

 TSomeClass = class
 private
   type
     TSomeType = type integer;    // an internal type
   class var
     FSomeClassVar: TSomeType;    // class variable belongs to a class, not an instance
   var
     FSomeIntanceVar: TSomeType;  // instance variable belongs to instance. it is a usual field
   class procedure SetSomeClassVar(const AValue: TSomeType); static;
 public
   class property SomeProperty: TSomeType read FSomeClassVar write SetSomeClassVar; // class property - belongs to a class
   property SomeInstanceProp: TSomeType read FSomeIntanceVar;
 end;

{ TSomeClass }

class procedure TSomeClass.SetSomeClassVar(const AValue: TSomeType); begin

  FSomeClassVar := AValue;

end;

var

 SomeClass: TSomeClass;

begin

 SomeClass.SomeProperty := 1;
 WriteLn(SomeClass.SomeProperty);

end. </delphi>