There are many RadioButton switches on the form. The task is to reset the button to them all in Checked = False
. How to solve a problem without referring to the object of each switch?
- +1 And yet this may not be entirely true - the meaning of the radio beats is just that an option is always selected. - Kromster
- @Kromster, in fact, the problem is slightly different. If I have RadioButtons on different GroupBox \ Panel, then when they turn out to be independent of each other. And I need to turn on only the selected switch. We have to invent bicycles in the form of push-ups of the rest))) - Robert
- Then ok. But I leave a comment to warn future readers) - Kromster
|
1 answer
Decided as follows (can someone come in handy)
var i: Integer; begin for i := 0 to ComponentCount - 1 do begin if (Components[i] is TRadioButton) then begin (Components[i] as TRadioButton).Checked := False; end; end; end;
- oneAnd why do you need TWinControl and its CanFocus? - kot-da-vinci 2:42 pm
- @ kot-da-vinci and really, thank you) - Robert
- oneBy the way, if RadioButton is very much, then you can make the optimal HMB: assign an OnClick () handler to each and do it in it:
FSelectedRB.Checked := False; FSelectedRB := Sender
FSelectedRB.Checked := False; FSelectedRB := Sender
, whereFSelectedRB
is a private form field, such as TRadioButton (not a component on a form!). Well, do not forget when creating a form to assign it a TRadioButton by default, so as not to get AV. This, moreover, will allow you to have several different TRadioButton groups on this form. - Alekcvp
|