943,914 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3463
  • C++ RSS
May 22nd, 2004
0

Better code for TCheckListBox

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elna is offline Offline
4 posts
since Mar 2004
May 24th, 2004
0

Re: Better code for TCheckListBox

whta is the program about? plz post it in like code
Team Colleague
Reputation Points: 55
Solved Threads: 3
Junior Poster
meabed is offline Offline
139 posts
since May 2004
May 25th, 2004
0

Re: Better code for TCheckListBox

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
Attached Files
File Type: zip c++.zip (497.9 KB, 25 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
elna is offline Offline
4 posts
since Mar 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Please Check The Errors'..Dont know what else to do
Next Thread in C++ Forum Timeline: Confused Where to Start?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC