Smart pascal source code
type
TTest = class
function GetProp(i: Integer): String;
procedure SetProp(i: Integer; v: String);
property Items[i: Integer]: String read GetProp write SetProp; default;
property Item1: String index 1 read GetProp write SetProp;
property Item2: String index 2 read GetProp write SetProp;
end;
function TTest.GetProp(i: Integer): String;
begin
Result := 'Get ' + IntToStr(i);
end;
procedure TTest.SetProp(i: Integer; v: String);
begin
WriteLn('Set ' + IntToStr(i) + ' with ' + v);
end;
var o := TTest.Create;
WriteLn(o[1]);
WriteLn(o[2]);
o[1] := 'hello';
o[2] := 'world';
WriteLn(o.Item1);
WriteLn(o.Item2);
o.Item1 := 'bye bye';
o.Item2 := 'test script';
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Get 1
Get 2
Set 1 with hello
Set 2 with world
Get 1
Get 2
Set 1 with bye bye
Set 2 with test script
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
var TTest = {
$ClassName:"TTest",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
}
,GetProp:function(Self, i) {
return "Get "+i.toString();
}
,SetProp:function(Self, i$1, v) {
WriteLn(("Set "+i$1.toString()+" with "+v));
}
,Destroy:TObject.Destroy
};
var o = null;
/* <<< main JS >>> */
o = TObject.Create($New(TTest));
WriteLn(TTest.GetProp(o,1));
WriteLn(TTest.GetProp(o,2));
TTest.SetProp(o,1,"hello");
TTest.SetProp(o,2,"world");
WriteLn(TTest.GetProp(o,1));
WriteLn(TTest.GetProp(o,2));
TTest.SetProp(o,1,"bye bye");
TTest.SetProp(o,2,"test script");