The codeline if (RadioBut.Checked = true) then ... gives an error: illegal qualifier.You declared RadioBut as string - strings doesn't have Checked property.
I have a radiogroup with 3 radiobuttons. I want to check if at least one of them is checked.
ETA: As Mark already said. Sorry, didn't see the other answers :-[
The code from lucamardidn't work. I stilll get the error when I select a radiobutton.
if MyRadioGroup.ItemIndex < 0 then
Lucamar's code: RadioGroup1.ItemIndex < 0 should not generate any error. It works on my test:
From code the OP posted it was obvious that he doesn't have control 'TRadioGroup', but individual 'TRadioButton'.
From code the OP posted it was obvious that he doesn't have control 'TRadioGroup', but individual 'TRadioButton'.
But OP's question specifically said "radiogroup", and he was doing something very odd with a string. I think we could usefully see more of what he's trying to do, since there's a possibility that he's abusing the controls in a way that will give him problems later on.
MarkMLl
Yes, he said radiogroup but from his code it was clear that he means 'group of radiobuttons'. He tried to access individual controls but he didn't use FindComponent.No, not clear at all. My example uses a TRadioGroup, accesses individual controls and does not use FindComponent. So, when somebody is accessing individual radiobuttons of a TRadioGroup does not necessarily mean that he is talking of a "TGroupbox" rather than a "TRadioGroup".
I attached small example.
Show us the whole source code, that is what I always ask. If OP provides the whole compile-able source code, the issue should be able to solve in minutes.
Yes, he said radiogroup but from his code it was clear that he means 'group of radiobuttons'. He tried to access individual controls but he didn't use FindComponent.No, not clear at all. My example uses a TRadioGroup, accesses individual controls and does not use FindComponent. So, when somebody is accessing individual radiobuttons of a TRadioGroup does not necessarily mean that he is talking of a "TGroupbox" rather than a "TRadioGroup".
I attached small example.
Of course, there are other ways to solve this. In your example it isn't shown how to check if any radio button is selected out of multiple TRadioGroups. And what if he has radio buttons outside of TGroupbox, just on the form?
No hard feelings.
Show us the whole source code, that is what I always ask. If OP provides the whole compile-able source code, the issue should be able to solve in minutes.
I posted my code 28 minutes after he asked and he said that it works for him.