Author: Tomas Rutkauskas
How can I set single Items.Strings in RadioGroups to Enabled := True or Enabled :=
False ?
Answer:
Solve 1:
1 TControl(RadioGroup1.Components[0]).Enabled := false;
2 TControl(RadioGroup1.Components[1]).Enabled := true;
Solve 2:
This function allows you to modify TRadioButtons in a given RadioGroup. Of course
you can modify this to search not for a caption but for an index:
3 4 function ButtonOfGroup(rg: TRadioGroup; SearchCaption: string): TRadioButton;
5 var6 i: Integer;
7 begin8 Result := nil;
9 for i := 0 to rg.ComponentCount - 1 do10 if (rg.Components[i] is TRadioButton) and11 (CompareStr(TRadioButton(rg.Components[i]).Caption, SearchCaption) = 0) then12 begin13 Result := TRadioButton(rg.Components[i]);
14 Break;
15 end;
16 end;
Solve 3:
The following code shows how to disable or enable an individual radio button in a
TRadioGroup component (the second radio button in this case). Note that the
RadioGroup.Controls is a zero based array.
17 18 procedure TForm1.Button1Click(Sender: TObject);
19 begin20 TRadioButton(RadioGroup1.Controls[1]).Enabled := False;
21 end;