| | |
Better code for TCheckListBox
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2004
Posts: 4
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Mar 2004
Posts: 4
Reputation:
Solved Threads: 0
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
Elna
![]() |
Similar Threads
- Code Snippet: Sample code for taking user input from Shell (Java)
- Code Snippet: code to split (and reconnect) an Access database (part 1) (Visual Basic 4 / 5 / 6)
- Code Snippet: Strings: Looking at ASCII Code (C)
- Code Snippet: Gray Code Conversion (C)
- Code Snippet: code to validate data in Access withOUT using messageboxes (Visual Basic 4 / 5 / 6)
- Code Snippet: code to split (and reconnect) an Access database (part 2) (Visual Basic 4 / 5 / 6)
- Code Snippet: Send HTML code to Internet Explorer from basic (Legacy and Other Languages)
Other Threads in the C++ Forum
- Previous Thread: How to incorporate Database into C++ ?
- Next Thread: Confused Where to Start?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





