Solved

Doesn't seem logical

Posted on 2014-09-04
8
233 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
  • 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
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.

 
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
Scripting vs. Programming languages 25 179
When i run adoquery my application freezes 26 180
SQL Insert parts by customer 12 43
does Jupiter 80 keyboard do chord recognition? 1 11
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

828 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