Class forward keyword



Class forward keyword
Pas2JS pascal source code
type TChild = class; type TBase = class function Stuff : TChild; virtual; abstract; end; type TChild = class (TBase) function Stuff : TChild; override; procedure WriteLnHello; class procedure WriteLnWorld; virtual; end; type TChild2 = class (TChild) function Stuff : TChild; override; class procedure WriteLnWorld; override; end; implementation function TChild.Stuff : TChild; begin Result:=Self; end; procedure TChild.WriteLnHello; begin WriteLn('Hello '); end; class procedure TChild.WriteLnWorld; begin WriteLn('World'); end; function TChild2.Stuff : TChild; begin Result:=inherited Stuff; end; class procedure TChild2.WriteLnWorld; begin WriteLn('My '); inherited WriteLnWorld; end; { unit1.pas } var o : TBase; c = o.Stuff; Begin o:=TChild.Create; c.WriteLnHello; o.Stuff.WriteLnWorld; o:=TChild2.Create; c:=o.Stuff; c.WriteLnHello; o.Stuff.WriteLnWorld; { ### CONSOLE OUTPUTS ### Hello World Hello My World }