I write software for testing specialists (knowledge check).
There is a group RADIOBUTTON
OS (3-10 elements).
Check:
Procedure TForm1.Button2Click (Sender: Togject);
Begin.
If RadioButton1.Checked = False and RadioButton2.Checked = False and ... RadioButton [n] .Checked = False Thatn
Begin.
ShowMessage ('To continue, select the answer.');
End.
ELSE.
Begin.
IF I & LT; = [N] THEN
Begin.
I: = i + 1;
(* Here we show the user questions.
And clean RadioButton *)
RadioButton1.Checked: = False;
....
RadioButton [n] .Checked: = False;
end;
end;
end;
The hint of me is that when creating a form, RadioButton’am is already set to Unchecked
. In order, the first discovered test was without Checked
RadioButton
And it happens, of course, when you first click the Button2 button, the event is triggered by the ShowMessage
event.
How to get around?
i.e. Whatever the first click of the button did not take RadioButton
ov.
Exit writing some index to the fact that clicking is the first?
Or is there something more universal and more traditional?
Supplement:
I make tracing, I put Check on any RadioButton, but the condition
if (RadioButton1.Checked = false and RadioButton2.checked = false and radiobutton3.checked = false) that
Begin.
ShowMessage ('To continue, knock out the answer.');
end;
still triggers.
(Something I was forgotten in 10 years.)
Answer 1, Authority 100%
Change the tag buttons, for example:
if (button2.tag == 0) then // If pressing happened for the first time
Begin.
Button2.tag: = 1;
Exit;
end;
ELSE.
// your actions
is just incomprehensible what’s the point.
p.s.: Ber / Bir
Roots with alternation.
Answer 2, Authority 150%
This problem is better to solve with the standard Radiogroup
component>.
This is the ready-made RadioButton
ore with the necessary functional. If no item is selected, the ItemIndex
property will be -1
, otherwise it will be equal to the index of the selected RadioButton
‘A (indexing starts with 0
).
Simplest example:
if radiogroup1.ItemIndex = -1 then
ShowMessage ('Select Option!')
ELSE.
ShowMessage ('Selected option -' + Radiogroup1.ItemS [Radiogroup1.ItemIndex]);
Answer 3, Authority 50%
I excluded a bad user in my practice. If he should not go to those until it selects one of the options, lock the continuation button.
onformshow (Sender: Togject);
Begin.
..
NextStePBTN.Enabled: = false;
..
End;
// Hang the handler to all RadioButton
ONRADIOBUTTONANYCLICK (Sender: Togject);
Begin.
..
// To all RadioButton not to go through check that at least one checked
If (Sender As TradioButton) .Checked then
NextStePBTN.Enabled: = True
ELSE // We do not know the state of others. Therefore, if although one checked, the next step will be available.
// If everything is unchecked the next step is not available
NextStepButton.Enabled: = ((RadioButton1.Checked) or (RadioButton2.Checked) .. OR (RadioButton [n] .Checked));
..
End;
OnNextStepButtonClick (Sender: Togject);
Begin.
..
// transition to the next step
NextStePBTN.Enabled: = false;
End;