Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Dynamic buttons array

124 views
Skip to first unread message

Jan Jaap Fahner

unread,
Aug 3, 1998, 3:00:00 AM8/3/98
to
Hi,

(using Borland C++ Builder 1.0)

I am creating buttons dynamically, and using an array
to store the pointers. I do this 'cause I don't know
how many buttons I'll need.
I've also written a trigger procedure that I assign to the
dynamic buttons.

Does anyone know how to determine which button
was pressed ? I could find the button for left-click
by finding the focus, but right-clicking doesn't focus
the button...

Thanks,

JJ

Jonathan Arnold

unread,
Aug 3, 1998, 3:00:00 AM8/3/98
to
> Does anyone know how to determine which button
> was pressed ? I could find the button for left-click

When you create the button, set its Tag value to something that you
can switch off of:

button_array[kk] = new TButton(this);
button_array[kk]->Tag = kk;

....

switch (button->Tag)
{
case 1:
...
}

+===================================================+
| Jonathan Arnold (mailto:jdar...@buddydog.org) |
| Senior Engineer Roger Wagner Publishing |
| http://people.ne.mediaone.net/jdarnold |
+===================================================+

"When a man's best friend is his dog, that dog has a problem."
Edward Abbey

Jon Jenkinson

unread,
Aug 3, 1998, 3:00:00 AM8/3/98
to
Hi Jan,

You need to dynamically assign an event handler of the correct type to
the event you need. For instance,

TButton *MyButton = new TButton(Application);

MyButton->OnClick = MyClickHandler;
MyButton->MouseDown = MyMouseDownHandler;

You then declare the two event functions manually and action
accordingly,

void __fastcall TForm1::MyClickHandler(TObject *Sender)
{
TButton *TempButton = reinterpret_cast <TButton *> (Sender);

//if you've got them in a list, you can do a routine to find the index
//in the list which has TempButton as it's pointer, or when you create
.//the button set the Tag property to the index position in the list
}

//not don't delete TempButton :)

HTH
Jon


Jan Jaap Fahner <J...@emea.progress.com> wrote:

>Hi,
>
>(using Borland C++ Builder 1.0)
>
>I am creating buttons dynamically, and using an array
>to store the pointers. I do this 'cause I don't know
>how many buttons I'll need.
>I've also written a trigger procedure that I assign to the
>dynamic buttons.
>

>Does anyone know how to determine which button
>was pressed ? I could find the button for left-click

Thomas Liu

unread,
Aug 3, 1998, 3:00:00 AM8/3/98
to
You just need to compare 'Sender' with your button pointers in your
event handlers.

e.g.

if( Sender == btn[0] )
{
...
}
else if( Sender == btn[1] )
{
...
}
...

On Mon, 03 Aug 1998 12:48:06 +0200, Jan Jaap Fahner

0 new messages