如何在 Delphi 中制作关于带有两个单选按钮的单选组的 if 语句
How do I make an if statement concerning a radiogroup with two radio buttons in Delphi
如何使用两个单选按钮创建关于 TRadioGroup
的 if 语句,以便在选中 TRadioGroup
中的特定单选按钮时输出文本。
TradioGroup.Items
具有这些值:
- 男
- 女
因此,当检查男性按钮时,它必须输出'Mr'
,如果检查了女性按钮,则必须输出'Ms'
向丰富的编辑。
使用ItemIndex
property of the TRadioGroup
作为
Case RadioGroup1.ItemIndex of
0: //Add Mr to RichEdit;
1: //Add Ms to RichEdit;
//else if needed
end;
如果你真的需要使用if
那么
if RadioGroup1.ItemIndex = 0 then
//Add Mr to RichEdit
else
if RadioGroup1.ItemIndex = 1 then
//Add Ms to RichEdit;
//else if needed
你没有指定是否将Clear
the TRichEdit
component before adding the string, Add
or Insert
字符串给它,甚至根据Index
用它替换另一个,因此我把它留给你,只写评论。
因为你有两个按钮(假设按 Mr
- Ms
的顺序),那么 TRadioGroup
组件的 ItemIdex
属性 将保持:
-1
如果选择了 none 个。
0
表示选择 'Mr'
。
1
表示选择 'Ms'
。
您可以使用 if 语句来确定如果某个事件发生会发生什么。
在 radioGroup 中,索引从开始计数
0
1个
2个
3个
等等
if TRadioGroup1.ItemIndex = 0 then
RedDisplay.Lines.add('Mr') //This displays Mr in the richedit
else
if TRadioGroup1.ItemIndex = 1 then
RedDisplay.Lines.Add('Ms') ; // this displays Ms in the richedit
//You can add an extra else if ,if there is another button in the radioGroup.
```
如何使用两个单选按钮创建关于 TRadioGroup
的 if 语句,以便在选中 TRadioGroup
中的特定单选按钮时输出文本。
TradioGroup.Items
具有这些值:
- 男
- 女
因此,当检查男性按钮时,它必须输出'Mr'
,如果检查了女性按钮,则必须输出'Ms'
向丰富的编辑。
使用ItemIndex
property of the TRadioGroup
作为
Case RadioGroup1.ItemIndex of
0: //Add Mr to RichEdit;
1: //Add Ms to RichEdit;
//else if needed
end;
如果你真的需要使用if
那么
if RadioGroup1.ItemIndex = 0 then
//Add Mr to RichEdit
else
if RadioGroup1.ItemIndex = 1 then
//Add Ms to RichEdit;
//else if needed
你没有指定是否将Clear
the TRichEdit
component before adding the string, Add
or Insert
字符串给它,甚至根据Index
用它替换另一个,因此我把它留给你,只写评论。
因为你有两个按钮(假设按 Mr
- Ms
的顺序),那么 TRadioGroup
组件的 ItemIdex
属性 将保持:
-1
如果选择了 none 个。0
表示选择'Mr'
。1
表示选择'Ms'
。
您可以使用 if 语句来确定如果某个事件发生会发生什么。 在 radioGroup 中,索引从开始计数 0 1个 2个 3个 等等
if TRadioGroup1.ItemIndex = 0 then
RedDisplay.Lines.add('Mr') //This displays Mr in the richedit
else
if TRadioGroup1.ItemIndex = 1 then
RedDisplay.Lines.Add('Ms') ; // this displays Ms in the richedit
//You can add an extra else if ,if there is another button in the radioGroup.
```