LiveBindings is a great technology built into Delphi and C++Builder for bypassing most of the code involved in a CRUD data cycle (Create, Read, Update and Delete Cycle). It can keep you out of massive amounts of technical debt. However, sometimes the standard LiveBindings method of binding some controls can be overly complex.

You can easily simplify your LiveBindings by using an invisible TEdit control. Basically you bind your field value to the TEdit and set the TEdit to Visible := False;. In the OnValidate event of the TEdit control you add code to update the REAL control you want to update (like a TTMSFMXSlider for example). In the OnChange event of the target control you send the updated value BACK to the invisible TEdit control and LiveBindings takes care of the rest. The TEdit control is bidirectional by default and will bind directly to a lot of field types. Whereas if you try to LiveBind directly to a Set, Enumeration, or SubRange it can be more difficult than it should be.

There are a lot of different ways to do this in LiveBindings but so far I am found this to be the easiest way. If you've got code snippets that do this easier (like using TLinkControlToField.AssigningValue or TMethodUtils.RegisterMethod) I'd like to hear about them so put them in the comments!

The demo I am providing over on GitHub shows how to bind a TFDMemTable field to a TEdit which updates a TTMSFMXSlider and is also bound to a TTMSFMXLiveGrid. You can change the switch, change the value in the TEdit, or change the value in the grid and all of the other values will automatically update. The code that pumps the switch change back to the TEdit is TLinkObservers.ControlChanged(SliderEdit); so you need to run this function to lock in the change. Here is the full code snippet from the demo but the real magic takes place in LiveBindings (the link to the demo source code is down below):

procedure TForm1.SliderEditValidate(Sender: TObject; var Text: string);
  case Text.ToInteger of
    0: Slider.State := ssOn;
    1: Slider.State := ssOff;

procedure TForm1.SliderStateChanged(Sender: TObject);
  case Slider.State of
    ssOn: SliderEdit.Text := '0';
    ssOff: SliderEdit.Text := '1';

Note: The demo uses TMS FMX UI Pack (don't leave home without it).


Head over to GitHub and download the full source code demonstrating this technique of using an invisible TEdit to easily LiveBind almost any control and value together in RAD Studio 10.2 Tokyo!

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder. Design. Code. Compile. Deploy.

Start Free Trial   Free Delphi Community Edition   Free C++Builder Community Edition   Upgrade Today  

  • Beautiful technique for sophisticated things.      For the specific case I managed to do the same by connecting the field with the switch in the live bindings designer, selecting the TLinkControlToField and setting the property CustomParse to IfThen(%s=False,0,1) The table field stores 0 and 1 and everything is bidirectional In the original example, I noticed that, always for the specific case, everything also works by eliminating the OnValidate event of the Slider and linking in the live bindings designer its IsChecked property with the field in BindSourceDB1 . Also the line of code    FDMemTable1.Post; It is not needed for operation Here is the link to the code on dropbox: I hope I have not misunderstood the juice of this technique with my example I wish you all a good day Mario