繁体   English   中英

如何在 Delphi 中使用复选框?

[英]How to use a checkbox in Delphi?

现在,我有代码:

begin
If odd(GetAsyncKeyState(VK_snapshot)) then
If CheckBox1.Checked then
begin

然后继续使用代码的 rest。 这是正确的做法,还是我做错了?

您建议的是确定是否选中复选框的完全合法的方法。 这样做的代码可能看起来像

if checkBox.Checked then begin
    //do whatever needed for checked checkbox
end

或者像这样

if checkBox.Checked then begin
    //do whatever needed for checked checkbox
end else begin
    //do whatever needed for unchecked checkbox
end

请记住,您从 Checked 属性中获取的值对应于您获取该值时复选框的 state。

if DT.FieldByName('name_of_checkbox').AsBoolean=True then begin ..... end;
// In this case dt is TADOquery that you had used in your program.

由于您使用的是 2 个 if 语句,因此您也可以将它们合并为一个:

if odd(GetAsyncKeyState(VK_snapshot)) and CheckBox1.Checked then
begin
  ...
  ...
end;

if 语句的第二部分 (checkbox1.Checked) 仅在第一个评估为 True 时才被评估。 (由于 Delphi 使用短路评估

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM