http://codeverge.com/embarcadero.cppbuilder.using/using-sender-to-determine-which/1068317
http://qc.embarcadero.com/wc/qcmain.aspx?d=70595
Using *Sender to determine which button triggered even
Sender 转换到TButtonItem
不能
TButtonItem *bi = static_cast<TButtonItem*>(Sender);
改用下面的方式
TCategoryPanel *CategoryPanel; for (int i = 0; i < TreeView1->Items->Count; i++) { if (TreeView1->Items->Item[i]->Level == 0) { CategoryPanel = new TCategoryPanel(CategoryPanelGroup1); CategoryPanel->PanelGroup = CategoryPanelGroup1; CategoryPanel->Caption = TreeView1->Items->Item[i]->Text; } TCategoryButtons * CategoryButtons; CategoryButtons = new TCategoryButtons(CategoryPanel); CategoryButtons->Parent = CategoryPanel; CategoryButtons->Align = alTop; CategoryButtons->Height = TreeView1->Items->Item[i]->Count * (this->Canvas->TextHeight("a") + 12); CategoryButtons->ButtonOptions << boFullSize; CategoryPanel->Height = CategoryButtons->Height + 20; TButtonCategory *ButtonCategory; ButtonCategory = new TButtonCategory(CategoryButtons->Categories); TButtonItem *bi; // CategoryButtons->Categories->Items[0]->Items //TButtonCollection* if (TreeView1->Items->Item[i]->HasChildren) { for (int j = 0; j < TreeView1->Items->Item[i]->Count; j++) { bi = new TButtonItem(CategoryButtons->Categories->Items[0]->Items); bi->Caption = TreeView1->Items->Item[i]->Item[j]->Text; } } } CategoryPanelGroup1->CollapseAll();
void __fastcall TForm28::CategoryButtons1Categories0Items0Click(TObject *Sender) { TCategoryButtons *cb = static_cast<TCategoryButtons*>(Sender); TButtonItem *bi = static_cast<TButtonItem*>(cb->SelectedItem); Caption = bi->Caption; }
CategoryButtons.BorderStyle=bsNone
CategoryButtons.ButtonHeight=40
CategoryButtons.ButtonWidth=100