Mirror

How to enable / disable single items in a TRadioGroup (Views: 710)


Problem/Question/Abstract:

How can I set single Items.Strings in RadioGroups to Enabled := True or Enabled := False ?

Answer:

Solve 1:

TControl(RadioGroup1.Components[0]).Enabled := false;
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:

function ButtonOfGroup(rg: TRadioGroup; SearchCaption: string): TRadioButton;
var
  i: Integer;
begin
  Result := nil;
  for i := 0 to rg.ComponentCount - 1 do
    if (rg.Components[i] is TRadioButton) and
      (CompareStr(TRadioButton(rg.Components[i]).Caption, SearchCaption) = 0) then
    begin
      Result := TRadioButton(rg.Components[i]);
      Break;
    end;
end;

<< Back to main page