Add items (objects subclasses types) to the end of an ARRAY - List ClassName
Pas2JS pascal source code
type
TTest = class
end;
type
TTestClass = class of TTest;
end;
var
c := TTestClass;
a: array of TObject;
t: array of TTest;
procedure Test(a: array of TTest);
begin
a.Add(TTest.Create);
a.Add(c.Create);
end;
begin
a.Add(TTest.Create);
a.Add(c.Create);
Writeln(a[0].ClassName); // TTest
Writeln(a[1].ClassName); // TTest
//------------------------
Test(t);
Writeln(t[0].ClassName); // TTest
Writeln(t[1].ClassName); // TTest
var Exception={
$ClassName: "Exception",
$Parent: TObject,
$Init: function () { FMessage="" },
Create: function (s,Msg) { s.FMessage=Msg; return s }
}
function $ToClassType(o) {
if (o===null) return o;
return o.ClassType
}
;
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 TTest = {
$ClassName:"TTest",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
function ClassName$1(Self$1) {
return "Helper1."+TObject.ClassName(Self$1);
}
var c = null, c = TTest;
var a = [], t = [];
function Test(a$1) {
a$1.push(TObject.Create($New(TTest)));
a$1.push(TObject.Create($NewDyn(c,"")));
};
a.push(TObject.Create($New(TTest)));
a.push(TObject.Create($NewDyn(c,"")));
WriteLn(ClassName$1($ToClassType(a[0])));
WriteLn(ClassName$1($ToClassType(a[1])));
Test(t);
WriteLn(ClassName$1($ToClassType(t[0])));
WriteLn(ClassName$1($ToClassType(t[1])));