tp.Object events
tp.Object is not a DOM object and it is not an EventTarget.
It has its own small Tripous event mechanism. A class that inherits from
tp.Object can call this.Trigger("MyEvent", args), and subscribers
can listen with Object.On("MyEvent", listener).
The listener receives a tp.EventArgs object, not a native browser event.
Args.EventName keeps the custom Tripous event name, Args.Sender
points to the object that fired the event, and any extra values passed to
Trigger() become properties of Args.
The example below uses DummyObject. Notice that DummyObject
extends tp.Object. That is why it has On(), Off(),
Once(), Trigger(), HasListeners(), and
EventsEnabled.
DummyObject fires MyTotallyCustomEvent
DummyObject is a very small class that extends tp.Object.
Its Fire() method calls this.Trigger("MyTotallyCustomEvent", ...).
Subscriber object with handleEvent(args)
A subscriber may be an object with a handleEvent(args) method.
We subscribe it with Dummy.On("MyTotallyCustomEvent", Subscriber.handleEvent, Subscriber)
so this inside handleEvent() points to the subscriber object.
Subscriber function
A subscriber may also be a simple function. The function receives the same
tp.EventArgs object.
Once, Off, and EventsEnabled
Once() removes the listener after the first call.
Off() removes a listener explicitly.
EventsEnabled = false temporarily stops event delivery.