Smart pascal source code
type
TNotifyEvent = Procedure(sender: TObject);
type
TMyObject = Class(TObject)
private
FEvent: TNotifyEvent;
Procedure setEvent(Value: TNotifyEvent);
public
Property OnClick: TNotifyEvent read FEvent write setEvent;
procedure Trigger;
End;
Procedure TMyObject.setEvent(Value: TNotifyEvent);
Begin
FEvent := Value;
end;
procedure TMyObject.Trigger;
begin
if Assigned(FEvent) then
FEvent(Self);
end;
Procedure HandleEvent(sender: TObject);
Begin
WriteLn('event triggered');
WriteLn(sender.ClassName);
end;
var mTemp: TMyObject;
mTemp := TMyObject.Create;
mTemp.Trigger;
mTemp.OnClick := HandleEvent;
// <--Throws compiler error "More arguments expected"
mTemp.Trigger;
{<<< RESULT - CONSOLE LOG >>>
-----------------------------
Errors >>>>
Hint: "onClick" does not match case of declaration ("OnClick") [line: 33, column: 7]
Result >>>>
event triggered
TMyObject
-----------------------------
{<<<<<<<<< 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 $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 ClassName$1(Self$1) {
return "Helper1."+TObject.ClassName($Check(Self$1,""));
}
var TMyObject = {
$ClassName:"TMyObject",$Parent:TObject
,$Init:function ($) {
TObject.$Init($);
$.FEvent = null;
}
,setEvent:function(Self, Value) {
$Check(Self,"").FEvent = Value;
}
,Trigger:function(Self) {
if ($Check(Self,"").FEvent) {
$CheckFunc($Check(Self,"").FEvent,"")(Self);
}
}
,Destroy:TObject.Destroy
};
function HandleEvent(sender) {
WriteLn("event triggered");
WriteLn(ClassName$1($ToClassType(sender)));
};
var mTemp = null;
/* <<< main JS >>> */
mTemp = TObject.Create($New(TMyObject));
TMyObject.Trigger(mTemp);
TMyObject.setEvent(mTemp,HandleEvent);
TMyObject.Trigger(mTemp);