Smart pascal source code
type
TBase = class
Field: string;
constructor Create; virtual;
end;
constructor TBase.Create;
begin
Field := 'Hello';
end;
type
TChild = class(TBase)
constructor Create; override;
end;
constructor TChild.Create;
begin
Field := 'World';
end;
type
TBaseClass = class of TBase;
{ TEST II }
Type
TBaseClass2 = Class
Constructor Create;// Virtual;
Begin
WriteLn(ClassName);
End;
End;
Type
TDescendant = Class(TBaseClass2)
End;
Type
TClassRef = Class Of TBaseClass2;
{ TEST III }
type
TMyControl = TObject;
type
TMyControlClass = class of TMyControl;
type
TMySubControl = class (TMyControl);
{ main.pas }
var
meta: TBaseClass;
obj1: TBase;
cr : TClassRef;
Begin
if Assigned(meta) then
Writeln('Assigned bug');
meta := TBase;
if not Assigned(meta) then
Writeln('Not Assigned bug');
obj1 := meta.Create;
meta := TChild;
var
obj2 = meta.Create;
if meta = TBase then
Writeln('Bug Equal TBase');
if meta <> TChild then
Writeln('Bug Not Equal TChild');
Writeln(obj1.Field);
Writeln(obj2.Field);
meta := nil;
if Assigned(meta) then
Writeln('Clear Assigned bug');
{ ### CONSOLE OUTPUTS ###
Hello
World
}
{ TEST II }
cr := TDescendant;
cr.Create;
{ ### CONSOLE OUTPUTS ###
TDescendant
}
{ TEST III }
WriteLn(TMyControl.ClassName);
WriteLn(TMyControlClass.ClassName);
WriteLn(TMySubControl.ClassName);
{ ### CONSOLE OUTPUTS ###
TObject
TObject
TMySubControl
}
var Exception={
$ClassName: "Exception",
$Parent: TObject,
$Init: function () { FMessage="" },
Create: function (s,Msg) { s.FMessage=Msg; return s }
}
function $NewDyn(c,z) {
if (c==null) throw Exception.Create($New(Exception),"ClassType is nil"+z);
var i={ClassType:c};
c.$Init(i);
return i
}
var meta = null;
var obj1 = null;
var cr = null;
var obj2 = null;
if (meta) {
WriteLn("Assigned bug");
}
meta = TBase;
if (!meta) {
WriteLn("Not Assigned bug");
}
obj1 = TBase.Create$6$($NewDyn(meta,""));
meta = TChild;
obj2 = TBase.Create$6$($NewDyn(meta,""));
if (meta==TBase) {
WriteLn("Bug Equal TBase");
}
if (meta!=TChild) {
WriteLn("Bug Not Equal TChild");
}
WriteLn(obj1.Field);
WriteLn(obj2.Field);
meta = null;
if (meta) {
WriteLn("Clear Assigned bug");
}
cr = TDescendant;
TBaseClass2.Create$5($NewDyn(cr,""));
WriteLn(ClassName$1(TObject));
WriteLn(ClassName$1(TObject));
WriteLn(ClassName$1(TMySubControl));
/// TMySubControl = class (TObject)
/// [line: 117, column: 4, file: uMain]
var TMySubControl = {
$ClassName:"TMySubControl",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
/// TBaseClass2 = class (TObject)
/// [line: 97, column: 2, file: uMain]
var TBaseClass2 = {
$ClassName:"TBaseClass2",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
/// constructor TBaseClass2.Create()
/// [line: 98, column: 15, file: uMain]
,Create$5:function(Self) {
WriteLn(TObject.ClassName(Self.ClassType));
return Self
}
,Destroy:TObject.Destroy
};
/// TDescendant = class (TBaseClass2)
/// [line: 105, column: 2, file: uMain]
var TDescendant = {
$ClassName:"TDescendant",$Parent:TBaseClass2
,$Init:function ($) {
TBaseClass2.$Init($);
}
,Destroy:TObject.Destroy
};
/// TBase = class (TObject)
/// [line: 72, column: 3, file: uMain]
var TBase = {
$ClassName:"TBase",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.Field = "";
}
/// constructor TBase.Create()
/// [line: 77, column: 19, file: uMain]
,Create$6:function(Self) {
Self.Field = "Hello";
return Self
}
,Destroy:TObject.Destroy
,Create$6$:function($){return $.ClassType.Create$6($)}
};
/// TChild = class (TBase)
/// [line: 83, column: 3, file: uMain]
var TChild = {
$ClassName:"TChild",$Parent:TBase
,$Init:function ($) {
TBase.$Init($);
}
/// constructor TChild.Create()
/// [line: 87, column: 20, file: uMain]
,Create$6:function(Self) {
Self.Field = "World";
return Self
}
,Destroy:TObject.Destroy
,Create$6$:function($){return $.ClassType.Create$6($)}
};