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