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

Ste*_*eve 4 delphi delphi-xe2 livebindings

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

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

Arj*_*pek 5

使用 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
Run Code Online (Sandbox Code Playgroud)

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