Is it possible to bind (using live-bindings) multiple components to an (non component) object?

2.1k Views Asked by At

I've got an object, let's call it Controller which is NOT a component, it has an enabled property. Can I use live-bindings to say bind it to the enabled properties of some components on a form? i.e if the enabled property of my component changes, components which are bound to it have their enabled property set accordingly?

I can see how to do it if TController was a TComponent descendent. I know I could wrap my TController in a component, but I'm asking if there is a direct way of doing this?

2

There are 2 best solutions below

0
On BEST ANSWER

That is possible with a 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'); will evaluate all relevant expressions. In example above Label1.Visible and Checkbox1.IsChecked

1
On

A few days ago I gave a presentation on LiveBindings in Delphi XE2 at our local Be-Delphi. I published the slides and a complete 'White Paper' or 'Tutoriald' document on my website. In the last chapter I have tried to explain how to bind components to a TPerson instance created at runtime. Maybe it has some interesting information for you :

Introduction to LiveBindings in Delphi XE2