Can anybody tell me if there is a better way to code the following problem than what I’ve included below? The problem that I can see with my code is if you had to add 20 shapes to the list then you would have to add 20 if statements to the TCheckListBoxClickCheck event which makes me think there must be a more concise and reusable way to code it. The problem is if you have a TCheckListBox with the names of two shapes, say Circle and Rectangle. If a name is checked the corresponding shape is visible. The code I have at present is,
void __fastcall TForm:: TCheckListBoxClickCheck(TObject *Sender)
{
if (TCheckListBox->Checked[TCheckListBox-->ItemIndex] == true)
{
if (TCheckListBox ->ItemIndex == 0)
Circle->Visible = true;
if (TCheckListBox ->ItemIndex == 1)
Rectangle->Visible = true;
}
else
{
if (TCheckListBox ->ItemIndex == 0)
Circle->Visible = false;
if (TCheckListBox ->ItemIndex == 2)
Rectangle->Visible = false;
}
}
Thanks
Elna