C++Introduction to C++Language FeatureLearn C++

How To Make C++ Data Bindings In Windows VCL Apps

What are LiveBindings? How can I create LiveBindings in C++ Builder VCL applications? How can I use LiveBindings in VCL applications? What are the LiveBindings Visual Components? Is there a simple LiveBindigs example for the C++ Builder VCL applications? Let’s answer these questions by demonstrating them using a C++ IDE.

What are LiveBindings?

LiveBindings is a data-binding feature supported by both the VCL and FireMonkey frameworks in RAD Studio. LiveBindings is an expression-based framework, which means it uses bindings expressions to bind objects to other objects or to dataset fields.

There is an official DockWiki web page by Embarcadero about the LiveBindings here, please check this official link if you want to see latest changes. Let’s start from there and give a simple example,

What are LiveBindings in C++?

How To Make C++ Data Bindings In Windows VCL Apps - visual livebinding

LiveBindings are based on relational expressions, called binding expressions, that can be either unidirectional or bidirectional. LiveBindings is also about control objects and source objects. By means of binding expressions, any object can be bound to any other object, simply by defining a binding expression involving one or more properties of the objects you want to bind together. For example, you can bind a TEdit control to a TLabel so that, when the text changes in the edit box, the caption of the label is automatically adjusted to the value evaluated by your binding expression. Another example is binding a track bar control to a progress bar so that the progress rises or lowers as you move the track bar.

We can connect to dataset fields, alter one or more properties of different objects, and so on. Because LiveBindings propagate, we can even alter properties of objects that are connected to other objects that are bound to a control object.

Can we have a simple example of using LiveBindings in C++ Builder?

With the RAD Studio C++ Builder, we can directly bind components visually and easily. Let’s see steps to use them,

1. How to Bind VCL Components Visually?

In general you can bind each element of a component with another element of a component. We just need to right click to a visual component that we want to bind. Let’s create a new C++ Builder VCL Windows application, drag an Edit (TEdit) and Label (TLabel) components from palette to your form and right click to a Label1 component, you will the pop-up menu and click to “Bind Visually…” menu as below,

How To Make C++ Data Bindings In Windows VCL Apps how to visually live bind

You will see that LiveBindings Designer window is opened with the visual components listed as below,

How To Make C++ Data Bindings In Windows VCL Apps bindings designer

2. How to Link Members?

In this LiveBindings Designer,
Here you can select all component by clicking the top bar of the component or you can select members of component that can bind with another member of the component. In this example we will bind Edit->Text property with Label1->Caption property. Thus, if we do any change in the Text of Edit1 this will be automatically copied to Caption of Label1. To do this, select Text of Edit1 and drag to Caption of Label1 as below,

How To Make C++ Data Bindings In Windows VCL Apps linking members

You will see a link moving with your mouse movements and Caption is now in Green fill color that means Text property is Bindable with the Caption property of Label1.Now you can release your mouse button to create a link between Text and the Caption. You will see your line will be changed to arrow.

How To Make C++ Data Bindings In Windows VCL Apps linking properties

3. How to Run VCL Applications with LiveBindings ?

Livebindings are automatically comes with your applications. Now we can run our simple application with live bindings, press F9 or choice Project->Run menu to run your application. When you change your Edit1 and press Enter key you will it is copied to Caption of the Label1 as below,

How To Make C++ Data Bindings In Windows VCL Apps example app in action

4. How to Delete a Link in LiveBindings Designer

We can easily select the link that want to delete and then you will see it is selected, you can use right click and the “Remoe Link” menu to delete or you can simply click Del key to delete them.

How To Make C++ Data Bindings In Windows VCL Apps deleting a link

5. How to See More Bindable Properties

Note that components have a lot of properties and methods, here listed basic properties. If you want to see more properties just left click to “…” at the bottom bar of the listed component in the LiveBindings Designer.

How To Make C++ Data Bindings In Windows VCL Apps seeing more bindable properties

6. How to Drag Components and Links in LiveBindings ?

You can easily drag listed components in the LiveBindings by using their top bar, drag them as you drag windows. You will see their links will be extended automatically, you can also drag links your proper positions for the better view.

7. How to Zoom In, Zoom Out, Rearrange, Fit, Restore the LiveBindings view?

In LiveBindings Designe, there is right bar with small icons. You can can easily Zoom, In Zoom Out, Rearrange, Fit, Restore LiveBindings view?

Here are some final notes on LiveBindings in C++ Builder

This is a very simple VCL example about how you can use LiveBindings with components. There is an official DockWiki web page by Embarcadero about the LiveBindings here, please check this official link if you want to see the latest changes.

Note that you can bind each member of this to any Data components too. For example, USERNAME to Label2->Caption, AGE to Label3->Caption. For more detailed examples please check the Database Section of LearnCPlusPlus.org and DocWiki of Embarcadero. There are many official and 3rd party components that support many ways to display your data.

C++ Builder has a lot of components and ways to connect different databases and to visualize results with many components like TTeeChart, TViewport3D as well as 3rd party components from vendors like TMS components. RAD Studio 11 has new updates on the most of these kinds of components.

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?