Smart pascal source code
type
TMyProc = procedure;
procedure Proc1;
begin
WriteLn('Proc1');
end;
procedure Proc2;
begin
WriteLn('Proc2');
end;
var p, pp: TMyProc;
try
p;
except
on E: Exception do
WriteLn(E.Message)
end;
p := Proc1;
pp := p;
p;
p := Proc2;
p();
pp;
pp := p;
pp();
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Function pointer is nil [line: 17, column: 5]
Proc1
Proc2
Proc1
Proc2
-----------------------------
{<<<<<<<<< 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 $W(e) { return e.ClassType?e:Exception.Create($New(Exception),e.constructor.name+", "+e.message) }
function $New(c) { var i={ClassType:c}; c.$Init(i); return i }
function $Is(o,c) {
if (o===null) return false;
return $Inh(o.ClassType,c);
}
;
function $Inh(s,c) {
if (s===null) return false;
while ((s)&&(s!==c)) s=s.$Parent;
return (s)?true:false;
}
;
function $CheckFunc(i,z) { if (i) return i; throw Exception.Create($New(Exception),"Function pointer is nil"+z); }
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 Proc2() {
WriteLn("Proc2");
};
function Proc1() {
WriteLn("Proc1");
};
var p = null;
var pp = null;
/* <<< main JS >>> */
try {
$CheckFunc(p,"")();
} catch ($e) {
var E = $W($e);
WriteLn($Check(E,"").FMessage) }
p = Proc1;
pp = p;
$CheckFunc(p,"")();
p = Proc2;
$CheckFunc(p,"")();
$CheckFunc(pp,"")();
pp = p;
$CheckFunc(pp,"")();