In C ++ Builder, you can put all your TCheckBox* pointers in an array or std::vector , which can then be executed if necessary, for example:
TCheckBox* cb[10]; __fastcall TForm1::TForm1(TComponent *Owner) : TForm(Owner) { cb[0] = CheckBox1; cb[1] = CheckBox2; ... cb[9] = CheckBox10; } void __fastcall TForm1::Button1Click(TObject *Sender) { for (int i = 0; i < 10; ++i) cb[i]->Checked = true; }
If you have many checkboxes and you do not want to fill the entire array manually, you can use a loop instead:
__fastcall TForm1::TForm1(TComponent *Owner) : TForm(Owner) { for (int i = 0; i < 10; ++i) cb[i] = (TCheckBox*) FindComponent("CheckBox" + IntToStr(i+1)); }
source share