delphi - 是否可以将多个组件绑定(bind)(使用实时绑定(bind))到一个(非组件)对象?

标签 delphi delphi-xe2 livebindings

我有一个对象,我们称之为 Controller ,它不是一个组件,它有一个启用的属性。我可以使用实时绑定(bind)将其绑定(bind)到表单上某些组件的启用属性吗?即,如果我的组件的启用属性发生变化,绑定(bind)到它的组件也会相应地设置其启用属性?

如果 TController 是 TComponent 的后代,我可以看到如何做到这一点。我知道我可以将 TController 包装在组件中,但我想问是否有直接的方法可以做到这一点?

最佳答案

这可以通过 BindScope 实现:BindScope1.DataObject := Controller;

  object BindingsList1: TBindingsList
    Methods = <>
    OutputConverters = <>
    UseAppManager = True
    Left = 464
    Top = 56
    object BindExpression1: TBindExpression
      Category = 'Binding Expressions'
      ControlComponent = Label1
      SourceComponent = BindScope1
      SourceExpression = 'enabled'
      ControlExpression = 'visible'
      NotifyOutputs = False
      Direction = dirSourceToControl
    end
    object BindExpression2: TBindExpression
      Category = 'Binding Expressions'
      ControlComponent = CheckBox1
      SourceComponent = BindScope1
      SourceExpression = 'enabled'
      ControlExpression = 'IsChecked'
      NotifyOutputs = False
      Direction = dirSourceToControl
    end
  end

TBindings.Notify(Controller, '启用');将评估所有相关表达式。在上面的示例中,Label1.Visible 和 Checkbox1.IsChecked

关于delphi - 是否可以将多个组件绑定(bind)(使用实时绑定(bind))到一个(非组件)对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7839339/

相关文章:

delphi - 如何解决这段代码中的字节顺序问题?

algorithm - Delphi - 编程算法找到下一个点来绘制组件

delphi - 弹出菜单没有出现在我的 Delphi 中

Delphi:使组件对实时绑定(bind)可见

Delphi 控制台应用程序 : how to add OnHelp to message dialogs?

delphi - Val 不适用于 UInt64?

delphi - 如何跨平台管理Delphi XE2的版本信息

delphi - Delphi XE2中调用 "IAudioSessionManager2.GetSessionEnumerator()"时出现异常

delphi - LiveBinding值无法通过代码设置