3

I am using Delphi XE3 with SP1. I have created a FireMonkey Desktop Application and dropped a TSpinBox and a TTrackBar on the main form. I have now connected the "Value" property of the TSpinBox and the TTrackBar using Visual Livebindings. The IDE has automatically created a "TLinkControlToProperty" to connect them. When I move the slider on the TTrackBar, the values in the TSpinBox change. But when I change the value in the TSpinBox, the value of the TTrackBar does not get updated.

How can I change this to a bidirectional connection using LiveBindings? My aim is to change the "Value" property of the TTrackBar, when the "Value" of the TSpinBox changes. Furthermore, I am interested in a solution that does not use the "OnChange" event of the "TSpinBox". Is this possible without deriving a descendant of "TSpinBox"?

Olaf Hess
  • 1,453
  • 11
  • 18

1 Answers1

3

You will have to add the Binding via Bindinglist, defining Source and Destination, set Direction to dirBiDirectional and add following code to your source:

procedure TForm1.SpinBox1Change(Sender: TObject);
begin
 BindingsList1.Notify(Sender, '');
end;

procedure TForm1.TrackBar1Change(Sender: TObject);
begin
 BindingsList1.Notify(Sender, '');
end;

Which can be reduced to

procedure TForm1.OneChangeEventForAllControlsUsingBindinglist1(Sender: TObject);
begin
 BindingsList1.Notify(Sender, '');
end;

enter image description here

bummi
  • 27,123
  • 14
  • 62
  • 101
  • Thanks for the answer. I should have been more explicit: I am interested in a solution that does not rely on using the "OnChange" events of the components. If I use "OnChange" I might as well get rid of the LiveBinding altogether. – Olaf Hess Jan 24 '13 at 12:11
  • I was not able to find solutions for bidirectional without code. You'd need only one Method for all of your controls Procedure TForm.OneFitsAll(Sender:TObject) with BindingsList1.Notify(Sender, ''); used in all ChangeEvents. – bummi Jan 24 '13 at 13:58
  • @Olaf `TSpinBox` did not notify the bindings on value change (maybe a bug). You can **a)** build your own `TSpinBox` which does or **b)** use the workaround with `OnChange` Event or **c)** report it on QC and wait for the update that will fix this. – Sir Rufo Jan 25 '13 at 00:58