Pre-Made Delegate Classes
To provide a cleaner, more pascal-like and type-safe experience, the QTX RTL includes a rich set of pre-built delegate classes that wrap the most common DOM events.
These classes are found in the qtx.dom.events.* units and are typically grouped by event type:
- Mouse Events: TQTXDOMMouseClickDelegate, TQTXDOMMouseDownDelegate, TQTXDOMMouseMoveDelegate, etc..
- Pointer Events: TQTXDOMPointerDownDelegate, TQTXDOMPointerMoveDelegate, TQTXDOMPointerLeaveDelegate, etc..
- Keyboard Events: TQTXDOMKeyboardDownDelegate, TQTXDOMKeyboardPressDelegate, TQTXDOMKeyboardUpDelegate.
- Touch Events: TQTXDOMTouchStartDelegate, TQTXDOMTouchMoveDelegate, TQTXDOMTouchEndDelegate, etc..
- Clipboard Events, Drag & Drop events
- And much, much more
Instead of using AddDelegate and typecasting, TQTXWidget provides helper functions (like AddPointerDownDelegate) that return an instance of that specialized delegate listener.
Compare the following two methods:
// Generic (Requires Typecasting)
MyWidget.AddDelegate('pointerdown',
procedure (Sender: TQTXDelegate; Event: JEvent)
begin
// Manual cast to JPointerEvent needed
var pEvent := JPointerEvent(Event);
WriteLn(pEvent.pointerId);
end
);
// Specialized (Type-Safe)
MyWidget.AddPointerDownDelegate(
procedure (Sender: TQTXDOMPointerDelegate; EventObj: JPointerEvent)
begin
// No cast needed! EventObj is already JPointerEvent
WriteLn(EventObj.pointerId);
end
);
When you are working in the IDE, these are the events you will typically use. Widget classes like TQTXButton use the [BindDelegates(...)] attribute to tell the IDE which of these pre-made delegates it can support.