In Delphi XE2 LiveBindings, I need to bind a VCL control of any type to a property of any type on an arbitrary (non-component) object. I can do this unidirectionally. But I need to do it bidirectionally.
Let's say I want to bind a TPerson.PersonName: string to a TEdit.Text.
What I have now is simple.
- Create a new VCL application, add a TBindScope, TBindingsList, TEdit.
- Create an instance of TPerson named person1.
- Using a BindingList, add a TBindExpression property.
- With BindExpression
- set ControlComponent to Edit1
- set ControlExpression to 'Text'
- set SourceComponent to BindScope1
- set SourceExpression to PersonName
- Add a button; to the Click event I add: BindScope1.DataObject := person1;
- Add a button; to the Click event I add (only one is necessary, but until it works I will try them both).
- TBindings.Notify(sender, '');
- BindingsList1.Notify(sender, '');
The first button binds in the first direction. The second button never seems to write the value back to the person1.PersonName property.
I've experimented with the notification code, the binding direction, binding types, expressions, SourceMember, etc. Sometimes I get runtime errors in the bindexpression configuration, the rest of the time the binding is simply unidirectional.
I expect to click the second button and see the contents of Edit1.Text written to person1.PersonName.
If I have to do this all from code, I'll consider it and such examples are welcome, but I really want to do it through the designer if possible.
Note that I am not interested in binding between two controls.
Note too that I have already downloaded and inspected the LiveBinding sample projects, and didn't find any that do this. If this is wrong, please be specific when pointing it out. I have also read the DocWiki. It does not cover bidirectional binding except using the DB LiveBinding controls. I am not using the DB LiveBinding controls nor am I using a DataSet. So unless you can explain to me why I should use them, I won't be needing any information about those controls.