Smart pascal source code
type
TTest = class
end;
procedure WriteLnArray(a: array of TObject);
begin
if a.Length = 0 then
WriteLn('Empty')
else
begin
var i: Integer;
for i := 0 to a.High do
begin
WriteLn(i);
WriteLn(' : ');
if a[i] = nil then
WriteLn('nil')
else
WriteLn(a[i].ClassName);
end;
end;
end;
var a: array of TObject;
var o := TObject.Create;
var t := TTest.Create;
WriteLnArray(a);
a := [nil];
WriteLnArray(a);
a := [o, t];
WriteLnArray(a);
a := [t, o];
WriteLnArray(a);
a := [o, nil];
WriteLnArray(a);
a := [nil, o];
WriteLnArray(a);
a := [];
WriteLnArray(a);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Empty
0 : nil
0 : TObject
1 : TTest
0 : TTest
1 : TObject
0 : TObject
1 : nil
0 : nil
1 : TObject
Empty
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
function WriteLnArray(a$1) {
var i = 0;
if (!a$1.length) {
WriteLn("Empty");
} else {
var $temp1;
for(i=0,$temp1=a$1.length;i<$temp1;i++) {
WriteLn(i);
WriteLn(" : ");
if ($DIdxR(a$1,i,"")===null) {
WriteLn("nil");
} else {
WriteLn(ClassName$1($ToClassType($DIdxR(a$1,i,""))));
}
}
}
};
var TTest = {
$ClassName:"TTest",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,Destroy:TObject.Destroy
};
var a = [],
o = null,
t = null;
/* <<< main JS >>> */
o = TObject.Create($New(TObject));
t = TObject.Create($New(TTest));
WriteLnArray(a);
a = [null].slice();
WriteLnArray(a);
a = [o, t].slice();
WriteLnArray(a);
a = [t, o].slice();
WriteLnArray(a);
a = [o, null].slice();
WriteLnArray(a);
a = [null, o].slice();
WriteLnArray(a);
a = [];
WriteLnArray(a);