Class var dynamic



Class var dynamic
Smart pascal source code
{ class var static } type TBase = class class var Test : Integer; end; type TChild = class (TBase) end; type TChildHide = class (TBase) class var Test : Integer := 456; end; { class var dynamic } type TBase = class Field : Integer; class var Test := 1; class const C = 10; class var Test2 := test + c; class procedure Hello; begin WriteLn('Hello'); WriteLn(Test2); end; class var HelloPtr := @Hello; end; type TBase2 = class Field : Integer; class var Test : Integer := 11; class procedure WriteLnIt; begin WriteLn(Test); end; constructor Create; begin Field:=Test; end; end; { main.pas } var b : TBase; c : TChild; ch : TChildHide; Begin { testing var static } WriteLn(TBase.Test); TBase.Test:=123; WriteLn(TBase.Test); WriteLn(TChild.Test); WriteLn(TChildHide.Test); WriteLn(b.Test); WriteLn(c.Test); WriteLn(ch.Test); WriteLn(TBase(ch).Test); { ### CONSOLE OUTPUTS ### 0 123 123 456 123 123 456 123 } { testing var dynamic } TBase.HelloPtr; { ### CONSOLE OUTPUTS ### Hello 11 } TBase2.WriteLnIt; WriteLn(TBase2.Create.Field); TBase2.Test:=22; TBase2.WriteLnIt; WriteLn(TBase2.Create.Field); { ### CONSOLE OUTPUTS ### 11 11 22 22 }