Method Implementation



Method Implementation
Smart pascal source code
type TMyClass = class FField: Integer; procedure SetField(f: Integer); begin FField := MaxInt(0, f); end; property Field: Integer read FField write SetField; procedure WriteLnMe; virtual; begin WriteLn(Field); end; end; type TMySubClass = class(TMyClass) procedure WriteLnMe; override; begin WriteLn('Sub-'); inherited; end; const cHello = 'Hello'; class function Hello: String; begin Result := cHello; end; end; var o := TMyClass.Create; o.Field := 3; o.WriteLnMe; o.Field := -o.Field; o.WriteLnMe; WriteLn(TMySubClass.Hello); o := TMySubClass.Create; o.Field := 3; o.WriteLnMe; WriteLn((o as TMySubClass).Hello); {<<< RESULT - CONSOLE LOG >>> ----------------------------- 3 0 Hello Sub-3 Hello ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}