Board index » cppbuilder » dynamically assigning an event handler

dynamically assigning an event handler

Hi,

I want to be able to dynamically create buttons (TButton) on demand. I will
use the Tag property for identity, and a common, existing (say OnClick)
event handler. But how can I programatically attach the newly created button
to that event handler ? Appreciate your ideas. Thanks.

- Lew Barnesson

 

Re:dynamically assigning an event handler


Look a few pages down in this newsgroup, for the first reply to this
message:

Date: Wed, 18 Oct 2000 11:57:53 +0300
ozan.kilicoglu@>
Newsgroups: borland.public.cppbuilder.vcl.components.using
Subject: How can I assign my event handler function of the dynamicaly
created vcl
-------
Timothy H. Buchman
========================================
City Center Theater, New York NY
mailto:tbuchmanREMOVE@NO_SPAMcitycenter.org
Please treat this signature information as confidential.
========================================
Search .borland message archive on http://www.mers.com/searchsite.html

Quote
Lew Barnesson <lewb...@msn.com> wrote in message

news:8ui7rv$86i8@bornews.inprise.com...
Quote
> Hi,

> I want to be able to dynamically create buttons (TButton) on demand.
I will
> use the Tag property for identity, and a common, existing (say
OnClick)
> event handler. But how can I programatically attach the newly
created button
> to that event handler ? Appreciate your ideas. Thanks.

> - Lew Barnesson

Re:dynamically assigning an event handler


Hi!

Quote
> But how can I programatically attach the newly created button
> to that event handler ?

in header:

void __fastcall MyOwnClickHandler(TObject *Sender);

in .cpp:

TButton *MyButton;

MyButton = new TButton(this);
MyButton->Parent = MyForm;   <- Dont forget to set the parent property
correctly!
MyButton->OnClick = MyOwnClickHandler;  <- Thats what youre asking for

And, of course, the handler itself:

void __fastcall MyForm::MyOwnClickHandler(TObject *Sender)
{
    /* Do your handling here */

Quote
}

Re:dynamically assigning an event handler


Timothy, Thanks. -Lew
"Timothy H. Buchman" <tbuch...@citycenter.org> wrote in message
news:8uiann$86g7@bornews.inprise.com...
Quote
> Look a few pages down in this newsgroup, for the first reply to this
> message:

> Date: Wed, 18 Oct 2000 11:57:53 +0300
> ozan.kilicoglu@>
> Newsgroups: borland.public.cppbuilder.vcl.components.using
> Subject: How can I assign my event handler function of the dynamicaly
> created vcl
> -------
> Timothy H. Buchman
> ========================================
> City Center Theater, New York NY
> mailto:tbuchmanREMOVE@NO_SPAMcitycenter.org
> Please treat this signature information as confidential.
> ========================================
> Search .borland message archive on http://www.mers.com/searchsite.html

> Lew Barnesson <lewb...@msn.com> wrote in message
> news:8ui7rv$86i8@bornews.inprise.com...
> > Hi,

> > I want to be able to dynamically create buttons (TButton) on demand.
> I will
> > use the Tag property for identity, and a common, existing (say
> OnClick)
> > event handler. But how can I programatically attach the newly
> created button
> > to that event handler ? Appreciate your ideas. Thanks.

> > - Lew Barnesson

Re:dynamically assigning an event handler


Thomas,
Just what I needed. Thanks. -Lew
Quote
"Thomas Blankschein" <tho...@blankschein.de> wrote in message

news:8ujp5n$pqa$06$1@news.t-online.com...
Quote
> Hi!

> > But how can I programatically attach the newly created button
> > to that event handler ?

> in header:

> void __fastcall MyOwnClickHandler(TObject *Sender);

> in .cpp:

> TButton *MyButton;

> MyButton = new TButton(this);
> MyButton->Parent = MyForm;   <- Dont forget to set the parent property
> correctly!
> MyButton->OnClick = MyOwnClickHandler;  <- Thats what youre asking for

> And, of course, the handler itself:

> void __fastcall MyForm::MyOwnClickHandler(TObject *Sender)
> {
>     /* Do your handling here */
> }

Other Threads