Delphi: How to assign dynamically an event handler without overwriting the existing event handler? -
i need loop through components , assign event handler (for example dynamically assigning onclick event tbutton to
showmessage('you clicked on ' + (sender tbutton).name);
the problem in cases assigned tbutton onclick event.
is there way solve problem?
let's imagine have button1 harcoded onclick event handler is:
showmessage('this button1');
after "parsing" full event handler button1 becomes:
showmessage('this button1'); // design time event handler code showmessage('you clicked on ' + (sender tbutton).name); // runtime added
note: looking soliution allows me use tbutton without inheriting it.
you assignment of onclick before overwriting it, persist , use in new handler - chaining events.
something this:
var original : tnotifyevent; original := component.onclick; component.onclick := newmethod;
and in newmethod:
if assigned(original) original(sender);
you'll not want single original variable instead hold collection keyed on component.
Comments
Post a Comment