Smart pascal source code
type
TBaseTemplate = class
class procedure Execute;
end;
type
TSubTemplate = class(TBaseTemplate);
type
TBaseTemplateClass = class of TBaseTemplate;
procedure Foo(FooClass: TBaseTemplateClass);
begin
WriteLn(FooClass.ClassName);
end;
class procedure TBaseTemplate.Execute;
begin
Foo(ClassType as TBaseTemplateClass);
Foo(TBaseTemplateClass(ClassType));
end;
{ main.pas }
Begin
TBaseTemplate.Execute;
TSubTemplate.Execute;
{ ### CONSOLE OUTPUTS ###
TBaseTemplate
TBaseTemplate
TSubTemplate
TSubTemplate
}
function $Inh(s,c) {
if (s===null) return false;
while ((s)&&(s!==c)) s=s.$Parent;
return (s)?true:false;
};
function $AsClass(s,c) {
if ((s===null)||$Inh(s,c)) return s;
throw Exception.Create($New(Exception),"Cannot cast class \""+s.$ClassName+"\" to class \""+c.$ClassName+"\"");
}
TBaseTemplate.Execute(TBaseTemplate);
TBaseTemplate.Execute(TSubTemplate);
function Foo(FooClass) {
WriteLn(ClassName$1(FooClass));
};
/// TBaseTemplate = class (TObject)
/// [line: 72, column: 3, file: uMain]
var TBaseTemplate = {
$ClassName:"TBaseTemplate",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
/// procedure TBaseTemplate.Execute()
/// [line: 87, column: 31, file: uMain]
,Execute:function(Self) {
Foo($AsClass(TObject.ClassType(Self),TBaseTemplate));
Foo($AsClass(TObject.ClassType(Self),TBaseTemplate));
}
,Destroy:TObject.Destroy
};
/// TSubTemplate = class (TBaseTemplate)
/// [line: 77, column: 3, file: uMain]
var TSubTemplate = {
$ClassName:"TSubTemplate",$Parent:TBaseTemplate
,$Init:function ($) {
TBaseTemplate.$Init($);
}
,Destroy:TObject.Destroy
};