Checkbox functionality? lazarus / 31-LCL ---------------------------------------------------------------------- Ruptor · 2013-03-03 11:35 I wanted to make two check boxes always be in the opposite state and thought it was a straightforward task but my first attempt didn't work.  It took two clicks to get a checkbox to turn on but the other checkbox was switched off on the first click. My logic was that if a checkbox is clicked it is set true so setting the other one to false would uncheck it. Clearly my logic is wrong but why? Code: [Select]// initialised to COGchk.checked:=false; procedure TForm1.COGchkChange(Sender: TObject); begin   EMAchk.checked:=false; end; procedure TForm1.EMAchkChange(Sender: TObject); begin   COGchk.checked:=false; end; I fixed the problem by using. Code: [Select]procedure TForm1.COGchkChange(Sender: TObject); begin   EMAchk.checked:=not COGchk.checked; end; procedure TForm1.EMAchkChange(Sender: TObject); begin   COGchk.checked:=not EMAchk.checked; end; ---------------------------------------------------------------------- taazz · 2013-03-03 11:42 You have just described the radio buttons, and to top it you do not take in to account what happens wen more than 2 check boxes are used and one is unchecked. ---------------------------------------------------------------------- Ruptor · 2013-03-03 12:01 Do you mean I should be using the radio buttons instead? I just thought having a tick positioned above what I wanted to show as selected looked better. I figured out what the problem was with my original code. I shouldn't have used "change" because of course when one change alters the other box the change is triggered and the routine is called for the other box. A bit of a recursive situation so I should be using "OnClick" instead. ---------------------------------------------------------------------- taazz · 2013-03-03 12:07 yes radio buttons would be hat I would use doesn't matter how or where they will appear. As for the problem I wouldn't use the click event you ignoring the the keyboard. use the change and have a flag set eg. Code: [Select]procedure TForm1.COGchkChange(Sender: TObject); begin   IF Fchanging then exit;   FChanging := true;   try     EMAchk.checked:=not COGchk.checked;   finally     FChanging := false;   end; end; procedure TForm1.EMAchkChange(Sender: TObject); begin   IF Fchanging then exit;   FChanging := true;   try     COGchk.checked:=not EMAchk.checked;   finally     FChanging := false;   end; end; ---------------------------------------------------------------------- Ruptor · 2013-03-03 12:51 OK Thanks for the help I will use it. ---------------------------------------------------------------------- Ruptor · 2013-03-03 13:26 I had the "OnClick" already coded so I tested it but it had the recursive problem as well. A change of check state is seen as a click of the checkbox which seems wrong to me. So it doesn't matter which method is used the other checkbox routine will get called unnecessarily and is a waste of cpu time. Perhaps I should use mouse and keypress instead but the value change might cause these to run too.