小编Se7*_*7en的帖子

一次只检查一个CheckBox

[编译:Delphi XE2]

昨天我花了一整天的时间尝试各种方法来完成这个特定的任务,但他们都以相同的结果结束了.

使用TRZCheckGroup和此示例查看已检查的内容等.

procedure TFrmMain.cbOptionsChange(Sender: TObject; Index: Integer; NewState: TCheckBoxState);
var
  ItmIndex0, ItmIndex1: Integer;
begin
  { Initialize ItemIndex's }
  ItmIndex0 := -1;
  ItmIndex1 := -1;

  { Return the position Index of the string's(0 and 1) }
  ItmIndex0 := cbOptions.Items.IndexOf('One');
  ItmIndex1 := cbOptions.Items.IndexOf('Two');

  { Which CheckBox has been Checked } 
  cbOptions.ItemChecked[ItmIndex0] := True;
  cbOptions.ItemChecked[ItmIndex1] := False;
end;
Run Code Online (Sandbox Code Playgroud)

注意:^这不是我的最终代码只是我如何处理CheckBoxes的一个例子.

像 -

if cbOptions.ItemChecked[ItmIndex0] then
  cbOptions.ItemChecked[ItmIndex1] := False
else cbOptions.ItemChecked[ItmIndex1] := True;
Run Code Online (Sandbox Code Playgroud)

他们第一次工作然后它总是评估为真,我理解为什么.当我取消检查第一个CheckBox时,else位才会生效,这显然不是我想要的结果.

似乎事件停止工作,并且由于某种原因,我的一些尝试已经解雇了两次.

关于cbListOptionsChange的NewState Param,这是什么,它能帮助我吗?

任何有关这方面的帮助将非常感激.

谢谢.

if cbOptions.ItemChecked[ItmIndex0] then
  cbOptions.ItemChecked[ItmIndex1] …
Run Code Online (Sandbox Code Playgroud)

delphi vcl delphi-xe2

1
推荐指数
1
解决办法
7746
查看次数

标签 统计

delphi ×1

delphi-xe2 ×1

vcl ×1