Smart pascal source code
type
TMyClass = class
procedure WriteLnMyName; virtual;
procedure WriteLnClassName;
end;
type
TChild = class(TMyClass)
procedure WriteLnMyName; override;
end;
procedure TMyClass.WriteLnMyName;
begin
Writeln('Ancestor: ' + ClassName);
end;
procedure TMyClass.WriteLnClassName;
begin
Writeln(ClassName);
end;
procedure TChild.WriteLnMyName;
begin
Writeln('I''m ' + ClassName);
end;
{ main.pas }
var
o: TObject;
c: TClass;
Begin
o := TObject.Create;
c := TObject;
Writeln(TObject.ClassName);
Writeln(o.ClassName);
Writeln(c.ClassName);
o := TMyClass.Create;
c := TMyClass;
TMyClass(o).WriteLnMyName;
TMyClass(o).WriteLnClassName;
Writeln(TMyClass.ClassName);
Writeln(o.ClassName);
Writeln(c.ClassName);
o := TChild.Create;
c := TChild;
TMyClass(o).WriteLnMyName;
TMyClass(o).WriteLnClassName;
Writeln(TChild.ClassName);
Writeln(o.ClassName);
Writeln(c.ClassName);
{ <<< CONSOLE OUTPUTS >>>
TObject
TObject
TObject
Ancestor: TMyClass
TMyClass
TMyClass
TMyClass
TMyClass
I'm TChild
TChild
TChild
TChild
TChild
}