Generic, Ad-Hoc Binding
The most direct way to listen to any DOM event is by using the AddDelegate method on TQTXWidget. You provide the event name as a string (e.g., 'input', 'scroll', 'pointerdown') and an anonymous procedure to act as the handler.
// Example: Ad-hoc binding to the 'input' event
MyMemo.AddDelegate('input',
procedure (Sender: TQTXDelegate; Event: JEvent)
begin
// 'Event' is a generic JEvent.
// We must typecast it to get specific properties.
WriteLn( JInputEvent(Event).data );
end
);
The power of this method is its flexibility—it works for every DOM event. The trade-off, as shown, is that you receive a generic JEvent and must manually typecast it to the correct event class (like JInputEvent, JMouseEvent, JPointerEvent) to access event-specific properties.