检测按钮是否在 Livecode 中启用或禁用

Detect if the Button is Enabled or Disabled in Livecode

如何在 livecode 中检测按钮是否为 enabled/disabled?

我想显示一个确定按钮是否为 disabled/enabled 的警告框。

我尝试了这些脚本,但它不起作用...

if button "button" is disabled then
   answer "button is disabled"
else
   answer "button is enabled"
end if

首先,我注意到您所有的脚本行都以大写开头。我建议您使用小写字符开始您的行。这将使您更加灵活地使用 LiveCode 脚本中典型的驼峰语法。

您不能将控件与常量进行比较。常量基本上是一个字符串,您只能将字符串与字符串进行比较。因为按钮是控件而不是字符串,所以不能比较按钮和常量。

其次,禁用是 属性 而不是常量。在您的脚本中,您对待它就像一个常量。 属性 始终是 "of a control",除非它是全局 属性。这意味着您需要在语法中包含 "of" 。你可以写the disabled of button "name of your button"。请不要使用 "button" 作为按钮的名称,因为这最终可能会使您和 LiveCode 引擎混淆。

以下脚本应该可以工作。

if the disabled of button "My Button" is true then
  answer "The button is disabled"
else
  answer "The button is enabled"
end if

因为 the disabled of button "My Button" returns truefalse 并且 the disabled of button "My Button" is true 也计算为 truefalse,你也可以只写

if the disabled of button "My Button" then
  answer "The button is disabled"
else
  answer "The button is enabled"
end if