Solved

Doesn't seem logical

Posted on 2014-09-04
8
235 Views
Last Modified: 2014-09-10
void __fastcall TForm1::CheckBox17Click(TObject *Sender)
{
   CheckBox17->State = cbChecked;
   CheckBox18->State = cbUnchecked;    
}
//---------------------------------------------------------------------------

void __fastcall TForm1::CheckBox18Click(TObject *Sender)
{
   CheckBox18->State = cbChecked;
   CheckBox17->State = cbUnchecked;  
 }

This code is in effect a closed loop.
The intention is to set box 17 to a checked state, and display it, and therefor Box 18 must be unset, and that to be displayed. And vice-versa.

There must be a 'right' way to do this?
0
Comment
Question by:VaughanMx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 27

Expert Comment

by:d-glitch
ID: 40303476
I don't think there is anything wrong with this at all.

When you click Box17, it is checked and Box18 is unchecked.
When you click Box18, it is checked and Box17 is unchecked.
The last action takes precedence.

Remember that a user may make a mistake or change his mind several times before he moves on.
This code seems logically correct and efficient to me.
It is proper event driven programming.
0
 

Author Comment

by:VaughanMx
ID: 40303654
What seems to be happening is that CheckBox18->State = cbUnchecked;  ,
when called from within the void __fastcall TForm1::CheckBox17Click(TObject *Sender) ,
actually calls void __fastcall TForm1::CheckBox18Click(TObject *Sender).

That description is a bit messy, so I hope you will persevere with it.

The checkboxes continuously call each other until the system runs out of memory.

I've obviously made a mistake here.
0
 
LVL 27

Expert Comment

by:d-glitch
ID: 40303743
I do understand your problem now, but I don't know how to fix it.
It is not really a logic problem.

On a click event, you want to call a function that makes two assignment statements.
The assignment statement should not call another function.
There is obviously a lot of additional code for setting up the form.  The problem is in there somewhere.

What language are you using?  I can't tell if it's C, Java, or Python.  
And the only one I might be able to help you with is  Python.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 500 total points
ID: 40303967
It might not be an elegant solution, but you could simply add a traffic cop.  Something like this:
bool bChecking = False;
void __fastcall TForm1::CheckBox17Click(TObject *Sender)
{
  if( ! bChecking )
  {
    bChecking = TRUE;
    CheckBox17->State = cbChecked;
    CheckBox18->State = cbUnchecked;    
    bChecking = FALSE;
  }
}
void __fastcall TForm1::CheckBox18Click(TObject *Sender)
{
  if( ! bChecking )
  {
    bChecking = TRUE;
    CheckBox18->State = cbChecked;
    CheckBox17->State = cbUnchecked;  
    bChecking = FALSE;
  }
}

Open in new window

0
 

Author Closing Comment

by:VaughanMx
ID: 40305285
Thanks HooKooDooKu, your suggestion works - maybe one day a more elegant solution will appear, but till then, thank you.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40308970
I realise that this question has already had an answer accepted, but I was just curious... The code that you give seems to basically just give you the functionality of what TRadioButton gives you for free, is there any reason why you didn't just use those?
0
 

Author Comment

by:VaughanMx
ID: 40313967
Thanks mccari- I didn't know that - it's exactly what I wanted to do
0
 
LVL 35

Expert Comment

by:mccarl
ID: 40314201
You're welcome! :)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Geek Squad recommended me a new machine for DAW digital audio projects. Are they right ? 1 82
ASP/VB email question 4 72
SQL Insert parts by customer 12 63
VLC command 34 83
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question