Link to home
Start Free TrialLog in
Avatar of VaughanMx
VaughanMxFlag for United States of America

asked on

Doesn't seem logical

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?
Avatar of d-glitch
d-glitch
Flag of United States of America image

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.
Avatar of VaughanMx

ASKER

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.
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.
ASKER CERTIFIED SOLUTION
Avatar of HooKooDooKu
HooKooDooKu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks HooKooDooKu, your suggestion works - maybe one day a more elegant solution will appear, but till then, thank you.
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?
Thanks mccari- I didn't know that - it's exactly what I wanted to do
You're welcome! :)