我不知道如何表示RadioGroup是否被选中,所以用了一种笨办法,
先设Items为“男”“女”程序如下:procedure TForm1.FormCreate(Sender: TObject);
begin
RadioGroup1.ItemIndex:=-1;
if (RadioGroup1.ItemIndex=-1) then
button1.Caption:='无';
if RadioGroup1.ItemIndex=0 then
button1.Caption:='男';
if RadioGroup1.ItemIndex=1 then
button1.caption:='女'
else
button1.Caption:='不男不女';
showmessage(inttostr(RadioGroup1.ItemIndex));
end;结果showMessage弹出-1,而button.caption为“不男不女”。真怪!
请问这是什么原因啊?正规的判断RadioGroup是否被选中的方法又是如何?
谢谢。
先设Items为“男”“女”程序如下:procedure TForm1.FormCreate(Sender: TObject);
begin
RadioGroup1.ItemIndex:=-1;
if (RadioGroup1.ItemIndex=-1) then
button1.Caption:='无';
if RadioGroup1.ItemIndex=0 then
button1.Caption:='男';
if RadioGroup1.ItemIndex=1 then
button1.caption:='女'
else
button1.Caption:='不男不女';
showmessage(inttostr(RadioGroup1.ItemIndex));
end;结果showMessage弹出-1,而button.caption为“不男不女”。真怪!
请问这是什么原因啊?正规的判断RadioGroup是否被选中的方法又是如何?
谢谢。
不信的话
你可以分别选中不同的记录
message出来后的结果都将是-1;
RadioButton1:
RadioButton2: if RadioButton1.Checked = true then
Button1.Caption := '男'
else
if RadioButton2.Checked = true then
Button1.Caption := '女'
else
Button1.Caption := '不男不女';