Mirror

Enable / disable single items in a TRadioGroup (Views: 5)

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;


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.

procedure TForm1.Button1Click(Sender: TObject);
begin
TRadioButton(RadioGroup1.Controls[1]).Enabled := False;
end;


<< Back to main page