放9个RadioButton控件,1个Botton控件 在Botton的OnClick事件事加入以下代码procedure TForm1.Button1Click(Sender: TObject); var iBs:Integer;//倍数 begin if RadioButton1.Checked then iBs:=1 else if RadioButton2.Checked then iBs:=2 else if RadioButton3.Checked then iBs:=3 else if RadioButton4.Checked then iBs:=4 else if RadioButton5.Checked then iBs:=5 else if RadioButton6.Checked then iBs:=6 else if RadioButton7.Checked then iBs:=7 else if RadioButton8.Checked then iBs:=8 else if RadioButton9.Checked then iBs:=9 procedure senddata(iBs); end;
begin
if RadioButton1.Checked then ShowMessage('1');
end;
在Botton的OnClick事件事加入以下代码procedure TForm1.Button1Click(Sender: TObject);
var
iBs:Integer;//倍数
begin
if RadioButton1.Checked then
iBs:=1
else if RadioButton2.Checked then
iBs:=2
else if RadioButton3.Checked then
iBs:=3
else if RadioButton4.Checked then
iBs:=4
else if RadioButton5.Checked then
iBs:=5
else if RadioButton6.Checked then
iBs:=6
else if RadioButton7.Checked then
iBs:=7
else if RadioButton8.Checked then
iBs:=8
else if RadioButton9.Checked then
iBs:=9
procedure senddata(iBs);
end;
senddata()函数加个参数,类型可以是integer或者string;则buttonClick代码:senddata(RadioGroup1.ItemIndex);//选中的按扭
senddata(RadioGroup1.Items.Strings[RadioGroup1.ItemIndex]);//选中按扭显示的名称
事件中
(变量名) := TRadioButton(Sender).tag;
正确!有RadioGroup组件不用户,非要整九个RadioButton ,这不没事找事吗!