TBitBtn *MyBitBtn[20];
for(int i=0;i < 20; i++)
{
MainForm->MyBitBtn[i] = new TBitBtn(this);
MainForm->MyBitBtn[i]->Parent = this;
MainForm->MyBitBtn[i]->OnClick = MyBitBtnClick;
MainForm->MyBitBtn[i]->Left = 8;
MainForm->MyBitBtn[i]->Top = hgt;
hgt = hgt + 25;
}
void __fastcall TMainForm::MyBitBtnClick(TObject *Sender)
{
How to tell which BitBtn was clicked?
}
Thanks
Jim Charest
for(int i=0;i<20;i++)
{
if(Sender = = MainForm->MyBitBtn[i])
{
strcpy(string,MainForm->MyBitBtn[i]->Caption.c_str());
Sender returns a pointer to the specific TBitBtn that triggered the event,
you don't need to iterate through your array looking for it.
void __fastcall TMyForm::MyBitBtnClick(TObject *Sender)
{
// Sender is a TObject*, but we need a TBitBtn*
TBitBtn *btn = dynamic_cast<TBitBtn*>(Sender);
// is Sender really a TBitBtn* ?
if( btn != NULL)
{
// yes, get the Caption
strcpy(string, btn->Caption.c_str());
}
}
Gambit