Better code for TCheckListBox

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2004
Posts: 4
Reputation: elna is an unknown quantity at this point 
Solved Threads: 0
elna elna is offline Offline
Newbie Poster

Better code for TCheckListBox

 
0
  #1
May 22nd, 2004
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
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 141
Reputation: meabed is on a distinguished road 
Solved Threads: 3
Team Colleague
meabed's Avatar
meabed meabed is offline Offline
Junior Poster

Re: Better code for TCheckListBox

 
0
  #2
May 24th, 2004
whta is the program about? plz post it in like code
Real Eyes Realize Real Lies
My Resume
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 4
Reputation: elna is an unknown quantity at this point 
Solved Threads: 0
elna elna is offline Offline
Newbie Poster

Re: Better code for TCheckListBox

 
0
  #3
May 25th, 2004
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, 5 views)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC