请问:RadioGroup如何表示被选中

sumury 2005-01-29 01:01:06
我不知道如何表示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是否被选中的方法又是如何?
谢谢。
...全文
222 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
sumury 2005-01-29
  • 打赏
  • 举报
回复
谢谢,程序通过!

谢谢!
Kshape_zh 2005-01-29
  • 打赏
  • 举报
回复
你可以假设你RadioGroup里面的按钮为:
RadioButton1:
RadioButton2:

if RadioButton1.Checked = true then
Button1.Caption := '男'
else
if RadioButton2.Checked = true then
Button1.Caption := '女'
else
Button1.Caption := '不男不女';
Kshape_zh 2005-01-29
  • 打赏
  • 举报
回复
RadioGroup1.ItemIndex

并不代表你选中的的项的序号
不信的话
你可以分别选中不同的记录
message出来后的结果都将是-1;

2,495

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧