Self



Self
Smart pascal source code
type TBase = class Field: Integer; procedure MyProc; function Virt: Integer; virtual; end; type TChild = class(TBase) function Virt: Integer; override; property Prop: Integer read Field; end; procedure TBase.MyProc; begin if Assigned(Self) then begin WriteLn(Self.ClassName); WriteLn(Self.Virt); end else WriteLn('nil'); end; function TBase.Virt: Integer; begin Result := Self.Field; end; function TChild.Virt: Integer; begin Result := Self.Prop * 100; end; var o: TBase; o.MyProc; try o.Virt; except on E: Exception do WriteLn(E.Message); end; o := TBase.Create; o.Field := 1; o.MyProc; o := TChild.Create; o.Field := 2; o.MyProc; {<<< RESULT - CONSOLE LOG >>> ----------------------------- nil Object not instantiated [line: 34, column: 6] TBase 1 TChild 200 ----------------------------- {<<<<<<<<< THE END >>>>>>>>>}