The delegate system is not limited to the pre-made classes for standard DOM events. The QTX RTL provides a complete framework for you to define, dispatch, and listen to your own custom events. This allows you to build complex components that can broadcast their state changes to any other part of your application in a clean, decoupled way.


The system is built on two key classes from qtx.delegates.pas:


  • TQTXEvent / TQTXCustomEvent: These are the event objects you create and dispatch (fire).
  • TQTXDelegate: This is the listener object you bind to an event's name.


A perfect example is found within the QTX RTL itself. The TQTXWindow component needs to tell its child components (like the header and footer) when it becomes focused or unfocused, so they can change their style.


It does this by defining and dispatching its own custom events, 'StyleFocused' and 'StyleUnFocused'.