Smart pascal source code
type
TObj1 = class
Field: TObject;
property Prop: TObject read Field;
function Get: TObject;
end;
type
TObj2 = class
Field: TObj1;
function GetItem: TObj1;
function GetObjField: TObject;
function GetObjProp: TObject;
function GetObjGet: TObject;
end;
function TObj1.Get: TObject;
begin
Result := Field;
end;
function TObj2.GetItem: TObj1;
begin
Result := Field;
end;
function TObj2.GetObjField: TObject;
begin
Result := GetItem.Field;
end;
function TObj2.GetObjProp: TObject;
begin
Result := GetItem.Prop;
end;
function TObj2.GetObjGet: TObject;
begin
Result := GetItem.Get;
end;
var o1 := new TObj1;
var o2 := new TObj2;
o2.Field := o1;
o1.Field := new TObject;
WriteLn(o2.GetItem.ClassName);
WriteLn(o2.GetObjField.ClassName);
WriteLn(o2.GetObjProp.ClassName);
WriteLn(o2.GetObjGet.ClassName);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
TObj1
TObject
TObject
TObject
-----------------------------
{<<<<<<<<< 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 $ToClassType(o) {
if (o===null) return o;
return o.ClassType
}
;
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
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 TObj2 = {
$ClassName:"TObj2",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.Field = null;
}
,GetItem:function(Self) {
return $Check(Self,"").Field;
}
,GetObjField:function(Self) {
return $Check(TObj2.GetItem(Self),"").Field$1;
}
,GetObjProp:function(Self) {
return $Check(TObj2.GetItem(Self),"").Field$1;
}
,GetObjGet:function(Self) {
return TObj1.Get(TObj2.GetItem(Self));
}
,Destroy:TObject.Destroy
};
var TObj1 = {
$ClassName:"TObj1",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.Field$1 = null;
}
,Get:function(Self) {
return $Check(Self,"").Field$1;
}
,Destroy:TObject.Destroy
};
var o1 = null,
o2 = null;
/* <<< main JS >>> */
o1 = TObject.Create($New(TObj1));
o2 = TObject.Create($New(TObj2));
$Check(o2,"").Field = o1;
$Check(o1,"").Field$1 = TObject.Create($New(TObject));
WriteLn(ClassName$1($ToClassType(TObj2.GetItem(o2))));
WriteLn(ClassName$1($ToClassType(TObj2.GetObjField(o2))));
WriteLn(ClassName$1($ToClassType(TObj2.GetObjProp(o2))));
WriteLn(ClassName$1($ToClassType(TObj2.GetObjGet(o2))));