Smart pascal source code
type
TTest = class
F: String := 'hello';
end;
var o := new TTest;
function Get: TTest;
begin
Result := o;
end;
WriteLn(o.F);
WriteLn(o.F[3]);
o.F[3] := 'z';
WriteLn(o.F);
WriteLn(o.F[3]);
Get.F[3] := 'y';
WriteLn(Get.F);
WriteLn(Get.F[3]);
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
hello
l
hezlo
z
heylo
y
-----------------------------
{<<<<<<<<< THE END >>>>>>>>>}
function $StrSetF(o,f,i,v,z) {
o[f]=$StrSet(o[f],i,v,z);
}
function $StrSet(s,i,v,z) {
if (i<1) throw Exception.Create($New(Exception),"Lower bound exceeded! Index "+i.toString()+z);
if (i>s.length) throw Exception.Create($New(Exception),"Upper bound exceeded! Index "+i.toString()+z);
return s.substring(0,i-1)+v+s.substring(i);
}
function $SIdx(s,i,z) {
if (i<1) throw Exception.Create($New(Exception),"Lower bound exceeded! Index "+i.toString()+z);
if (i>s.length) throw Exception.Create($New(Exception),"Upper bound exceeded! Index "+i.toString()+z);
return s.charAt(i-1);
}
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); } };
var TTest = {
$ClassName:"TTest",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.F = "hello";
}
,Destroy:TObject.Destroy
};
function Get() {
return o;
};
var o = null;
/* <<< main JS >>> */
o = TObject.Create($New(TTest));
WriteLn($Check(o,"").F);
WriteLn($SIdx($Check(o,"").F,3,""));
$Check(o,"").F = $StrSet($Check(o,"").F,3,"z","");
WriteLn($Check(o,"").F);
WriteLn($SIdx($Check(o,"").F,3,""));
$StrSetF($Check(Get(),""),"F",3,"y","");
WriteLn($Check(Get(),"").F);
WriteLn($SIdx($Check(Get(),"").F,3,""));