Delphi: How to assign dynamically an event handler without overwriting the existing event handler?
Posted
by
user193655
on Stack Overflow
See other posts from Stack Overflow
or by user193655
Published on 2010-12-21T16:38:55Z
Indexed on
2010/12/21
16:54 UTC
Read the original article
Hit count: 169
delphi
|event-handling
I need to loop through Components and assign an event handler (for example Dynamically assigning OnClick event for all TButton to
ShowMessage('You clicked on ' + (Sender as TButton).Name);
The problem is that in some cases I alreasy assigned the TButton OnClick event.
Is there a way to solve the problem?
Let's imagine I have Button1 for which the harcoded onclick event handler is:
ShowMessage('This is Button1');
After my "parsing" I would like that the full event handler for Button1 becomes:
ShowMessage('This is Button1'); // design time event handler code
ShowMessage('You clicked on ' + (Sender as TButton).Name); // runtime added
Note: I am looking for a soliution that allows me to use TButton as it is without inheriting from it.
© Stack Overflow or respective owner