(radiobutton1.Controls[0] as TradioButton).Checked:=true;
procedure TForm1.FormCreate(Sender: TObject); begin RadioButton1.Tag := 1; RadioButton2.Tag := 2; end;procedure TForm1.Button1Click(Sender: TObject); begin if TRadioButton(Self).Tag = 1 then begin RAdioButton1.Checked := true; end else begin RadioButton2.Checked := true; end; end;
procedure SetRadioButton(ItemIndex: Integer); var i:integer; begin for i:=0 to self.componentcount-1 do if (self.components[i] is TRadioButton) and (TRadioButton(self.components[i]).Tag:= ItemIndex) then begin TRadioButton(self.components[i]).Checked:= True; break; end; end;注:事先为每个RadioButton设置Tag属性。
begin
RadioButton1.Tag := 1;
RadioButton2.Tag := 2;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if TRadioButton(Self).Tag = 1 then
begin
RAdioButton1.Checked := true;
end
else
begin
RadioButton2.Checked := true;
end;
end;
var
i:integer;
begin
for i:=0 to self.componentcount-1 do
if (self.components[i] is TRadioButton) and
(TRadioButton(self.components[i]).Tag:= ItemIndex) then
begin
TRadioButton(self.components[i]).Checked:= True;
break;
end;
end;注:事先为每个RadioButton设置Tag属性。