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

时间:2011-10-20 16:48:54

标签: delphi delphi-xe2 livebindings

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

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

2 个答案:

答案 0 :(得分:4)

使用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,'Enabled');将评估所有相关的表达。在上面的示例Label1.Visible和Checkbox1.IsChecked

答案 1 :(得分:1)

几天前,我在当地的Be-Delphi上发表了关于Delphi XE2 LiveBindings的演讲。我在我的网站上发布了幻灯片和一份完整的“白皮书”或“Tutoriald”文档。在上一章中,我试图解释如何将组件绑定到在运行时创建的TPerson实例。也许它有一些有趣的信息给你:

Introduction to LiveBindings in Delphi XE2