954,190 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Better code for TCheckListBox

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

elna
Newbie Poster
4 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

whta is the program about? plz post it in like code;)

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

As I am only just beginning to learn programming the program is very straight forward. The files are attached in a zip document. The program works as it is supposed to. I’m not sure if it makes any difference but I am using C++ Builder 5. So basically can anybody see a better way to code the problem so that if more shapes were added you would not have to write an if statement for each shape?

Elna

Attachments c++.zip (497.88KB)
elna
Newbie Poster
4 posts since Mar 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You