The difference between traditional procedural-events and multi-cast delegates can be thought of as such:


  • Traditional: A property that holds a single reference to a procedure
  • Delegate: An object that manages a list of "listener objects", all of which get notified when the event fires, who in turn calls a handler procedure. All delegate objects (listeners) have their own unique handler procedure. You can attach as many delegate listeners as you like to the same event.


So instead of assigning a single procedure to an event, you create a delegate listener object and bind that to an event a component exposes. You can bind multiple, independent delegate objects to the very same event on the same component. When that event fires, the component doesn't just call one procedure; it notifies every listener in the same order as you added them.


This approach is fundamental to Quartex Pascal because it is a perfect, object-oriented wrapper for the native JavaScript multi-cast event system.

Behind the scenes, the TQTXDOMDelegate class invokes JavaScript's addEventListener() and removeEventListener() whenever you attach or detach from the event.


This allows for a much more flexible and decoupled architecture. Your form can bind a delegate to a button's click event, while a separate logging class can also bind to that same click event. All without interfering with each other.


While many components still offer simple Delphi-style event properties like OnClick for convenience (as seen on TQTXCustomButton), the true power of the event system is exposed through the pre-built delegate classes. It is also very easy to attach a delegate to any event (more about that later).


Quartex Pascal thus provides two powerful ways to handle DOM events on your widgets.