4

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?

LU RD
  • 34,438
  • 5
  • 88
  • 296
Steve
  • 6,382
  • 3
  • 41
  • 66

2 Answers2

5

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

Arjen van der Spek
  • 2,630
  • 16
  • 20
2

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

Stefaan
  • 492
  • 4
  • 19
  • link is broken, but can find its material at: https://web.archive.org/web/20190622014700/http://www.devia.be/news/article/introduction-to-livebindings-in-delphi-xe2/ - https://www.slideshare.net/StefaanLesage/bedelphi-livebindings-in-delphi-xe2-devia - https://www.scribd.com/document/73106743/Be-Delphi-Live-Bindings (probably LiveBindings have evolved since then though) – George Birbilis Aug 06 '22 at 13:37