Smart pascal source code
type
TClassA = class(TObject);
type
TClassB = class
end;
var a1: array of function: TClass;
a1.Add(TObject.ClassType);
a1.Add(TClassA.ClassType);
a1.Add(TClassB.ClassType);
//var a2: array of function: String;
var a2: array of String;
a2.Add(TObject.ClassName);
a2.Add(TClassA.ClassName);
a2.Add(TClassB.ClassName);
var i: Integer;
for i := 0 to High(a1) do
WriteLn(a1[i]().ClassName);
for i := 0 to High(a2) do
WriteLn(a2[i]);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
TObject
TClassA
TClassB
TObject
TClassA
TClassB
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TObject={
$ClassName: "TObject",
$Parent: null,
ClassName: function (s) { return s.$ClassName },
ClassType: function (s) { return s },
ClassParent: function (s) { return s.$Parent },
$Init: function () {},
Create: function (s) { return s },
Destroy: function (s) { for (var prop in s) if (s.hasOwnProperty(prop)) delete s.prop },
Destroy$: function(s) { return s.ClassType.Destroy(s) },
Free: function (s) { if (s!==null) s.ClassType.Destroy(s) }
}
var Exception={
$ClassName: "Exception",
$Parent: TObject,
$Init: function () { FMessage="" },
Create: function (s,Msg) { s.FMessage=Msg; return s }
}
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
function $Event0(i,f) {
var li=i,lf=f;
return function() {
return lf.call(li,li)
}
}
function $DIdxR(a,i,z) {
if (i<0) throw Exception.Create($New(Exception),"Lower bound exceeded! Index "+i.toString()+z);
if (i>a.length) throw Exception.Create($New(Exception),"Upper bound exceeded! Index "+i.toString()+z);
return a[i];
}
function $CheckFunc(i,z) { if (i) return i; throw Exception.Create($New(Exception),"Function pointer is nil"+z); }
function $Check(i,z) { if (i) return i; throw Exception.Create($New(Exception),"Object not instantiated"+z); }
function WriteLn(value) {
if (window.console) { window.console.log(value); } };
function ClassName$1(Self$1) {
return "Helper1."+TObject.ClassName($Check(Self$1,""));
}
var TClassB = {
$ClassName:"TClassB",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
var TClassA = {
$ClassName:"TClassA",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
var a1 = [],
a2 = [],
i = 0;
/* MAIN JS CODE */
a1.push($Event0(TObject, TObject.ClassType));
a1.push($Event0(TClassA, TObject.ClassType));
a1.push($Event0(TClassB, TObject.ClassType));
a2.push(ClassName$1(TObject));
a2.push(ClassName$1(TClassA));
a2.push(ClassName$1(TClassB));
var $temp1;
for (i = 0, $temp1 = a1.length; i < $temp1; i++) {
WriteLn(ClassName$1($CheckFunc($DIdxR(a1, i, ""), "")()));
}
var $temp2;
for (i = 0, $temp2 = a2.length; i < $temp2; i++) {
WriteLn($DIdxR(a2, i, ""));
}