Board index » cppbuilder » Assigning event handlers to dynamicaly created objects

Assigning event handlers to dynamicaly created objects

Hi,
Well, my subject pretty much says it all
I want to assign event handlers to components created in run-time
Suppose a button click
Thanks
 

Re:Assigning event handlers to dynamicaly created objects


Hi, George!

Quote
George Laskaris wrote:
> Well, my subject pretty much says it all
> I want to assign event handlers to components created in run-time
> Suppose a button click
> Thanks

Do the next:
1. Create a new method for your form. Let's name it YouNewButtonClick.
It must has the same parameters as event hanler. In this case "TObject*
Sender".
2. In code:
        Create your new button and just assign YouNewButtonClick on
OnClick handler

       NewButton=new TButton(this);
       NewButton->OnClick=YourNewButtonClick;

3. Just for a note (as I told above): this function must has the same
parameters as event handler. That is if you are going to assign the
handler for event OnKeyDown, your function must have parameters
"(System::TObject* Sender, Word &Key, Classes::TShiftState Shift)" like
OnKeyDown has.

--
Visit my page : http://sergeiss.narod.ru/
BCB components : http://sergeiss.narod.ru/BCB_eng.htm
| )))))
|
|___
|ooo|
|ooo|
|ooo|
|___|
Sergei.

Re:Assigning event handlers to dynamicaly created objects


Hi,
Well, my subject pretty much says it all
I want to assign event handlers to components created in run-time
Suppose a button click
Thanks

Other Threads