virtual_constructor I



virtual_constructor I
Smart pascal source code
type TClassA = class protected str: string; public constructor Create; virtual; class procedure Test; virtual; property strProp: String read str; end; type TClassB = class(TClassA) public constructor Create; override; class procedure Test; reintroduce; end; constructor TClassA.Create; begin str := 'A'; end; class procedure TClassA.Test; begin WriteLn('TestA'); end; constructor TClassB.Create; begin str := 'B'; end; class procedure TClassB.Test; begin WriteLn('TestB'); end; var cls: class of TClassA; var o: TClassA; cls := TClassB; o := cls.Create; WriteLn(o.strProp); o.Test; // call static method TClassB(o).Test; {<<< RESULT - CONSOLE LOG >>> ----------------------------- Errors >>>> Hint: "test" does not match case of declaration ("Test") [line: 52, column: 3] Hint: "test" does not match case of declaration ("Test") [line: 53, column: 12] Result >>>> B TestA TestB ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}