LiveBindings in RAD Studio
Go Up to Getting Started with RAD Studio
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.
LiveBindings is 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.
In the same manner, you can connect to dataset fields, alter one or more properties of different objects, and so on. Because LiveBindings propagates, you can even alter properties of objects that are connected to other objects that are bound to a control object.
The primary way to create bindings is using the LiveBindings Designer. It can only create QuickBindings components. The graph can show bindings of other components (such as TBindLink), but you cannot move the end points as you can with QuickBinding components.
There is a second way to create such bindings, using the LiveBindings Wizard. It also only creates QuickBinding components.
The LiveBindings Designer uses QuickBindings to create these type of bindings (which is also reflected in the wizard):
- Link a control such as TEdit to a field in a data source
- Link a control such as a TGrid to a data source
- Link a control such as TEdit to a component property (such a TLabel.Text)
- Link a component property to a field in a data source
A control can only link to one end point. So if a TEdit is linked to a field and you try to link the TEdit to a component property, the link to the field will be deleted. Also, a component property can link to one end point. Data sources and data source members can link to multiple end points. For example, a field can be linked to a TEdit and also to a TLabel. There would be two binding components involved.
Even though the LiveBindings Designer does not allow a control to link to two other component properties, it is possible to get this effect by linking the control and the component properties to a single field. The TPrototypeBindSource can be used to create a field for this purpose.
The term Link used in LiveBindings and API documentation indicates that the bindings acknowledge changes made by the user and automatically update controls and data sources to respond to user input.
You can use LiveBindings in VCL and FireMonkey applications by means of the LiveBindings Designer or the LiveBindings Wizard, which can be invoked either through the Object Inspector or by right-clicking individual components placed on the form (but only if it is enabled from the Tools > Options > LiveBindings dialog box). However, there is a hard way to use LiveBindings programatically in Console Applications, if for some reason you need to do this. Refer to the Creating LiveBindings, New LiveBinding or LiveBindings Wizard topic for a quick overview on how to create LiveBindings in RAD Studio.
- Tutorials on how to use LiveBindings in VCL or FMX applications using the LiveBindings Designer:
- Quick way (QuickBindings) of seamlessly creating LiveBindings using the LiveBindings Wizard:
- Tutorials on how to use LiveBindings in VCL or FMX applications using the LiveBindings Wizard:
- Tutorial: Using LiveBinding in VCL Applications (exemplifies VCL Application property binding)
- Tutorial: Using LiveBindings in FireMonkey Applications (exemplifies FireMonkey HD Application property binding)
- Tutorial: Using LiveBinding to Create an Application Without Code (exemplifies a FireMonkey HD Application built using LiveBindings)
- Tutorial: Using LiveBinding Programatically (only suitable for Console Applications or manual expression editing)
LiveBindings Visual Components
The LiveBindings engine is a run-time feature, but a number of visual components are present in the component palette, to help you create live bindings between components at design time. However, most of the time you will be creating bindings in a visually manner, using the LiveBindings Wizard.
If you browse the component palette, in the LiveBindings tab, there are the following components that you can drag and drop to a form (either VCL or FMX).
|Component Logo||Component Name||Description|
|TBindSourceDB||Is used for creating bindings to databases.|
|TPrototypeBindSource||Provides a data source for generating sample data that you can use to get started when you do not already have data to start with. Later you can replace this data source with some real data.|
|TBindingsList||Is used for holding of binding lists.|
|TBindScope||Is used for bindings to components.|
|TDataGeneratorAdapter||Is an adapter for data generators.|
|TAdapterBindSource||Is used for working with non-database data. The adapter property is used to connect the data source to non-database data, such as a generic collection of objects.|
|TBindNavigator (FMX)||Is used for cycling through records in a dataset when developing FMX applications.|
|TBindNavigator (VCL)||Is used for cycling through records in a dataset when developing VCL applications.|
Tip: When you use the Object Inspector to create live bindings between components, the appropriate LiveBindings component (TBindingsList) is automatically placed on the form. This component holds a list of all bindings available in your application. See the Bindings Lists topic for more information about binding lists.
There are a number of LiveBindings sample applications shipped along with RAD Studio that you can find by clicking Start | Programs | Embarcadero RAD Studio XE3 | Samples. The folder of interest is Delphi\LiveBinding. These samples are listed in the following table, divided by their corresponding category (FMX or VCL). Some of the sample applications are available for both FMX and VCL while others are available for only one of these two categories. The main project group for all the LiveBindings samples is called BindSamplesGroup.groupproj.
Tip: For information on how to update the Samples directory to the latest SVN version, please refer to the Sample help topic.
|FMX LiveBindings Samples||VCL LiveBindings Samples|
These samples show you in detail how to build enhanced applications using LiveBindings.
The source for the LiveBindings samples in your product installation are checked into a public Subversion repository that can be found on SourceForge:
LiveBindings API Reference
The following units are part of the LiveBindings engine. The documentation in their appropriate help topics contains information regarding LiveBindings API usage.
|System.Bindings.CustomScope||Custom scope-related classes|
|System.Bindings.CustomWrapper||Custom wrapper-related classes|
|System.Bindings.EvalProtocol||Interfaces used by the engine for the wrappers, scopes, and other internal structures|
|System.Bindings.Expression||Binding expression-related classes|
|System.Bindings.ExpressionDefaults||Default behavior for binding expressions|
|System.Bindings.Factories||Factories for expressions, managers, and scopes|
|System.Bindings.Helper||Tools for programmatic creation of binding expressions and for notifications|
|System.Bindings.Manager||Binding manager-related implementations|
|System.Bindings.ManagerDefaults||Default behavior for binding managers|
|System.Bindings.Methods||Control of methods that can be used in the script|
|System.Bindings.Outputs||Tools for control of expression outputs|
|Data.Bind||Contains units with implementations for the LiveBindings components|
Hint: When using C++Builder to develop console applications that make use of LiveBindings, you have to explicitly instruct the C++ compiler to generate RTTI information for the classes in your project. To do this, add the
#pragma explicit_rtti methods()directive at the beginning of your project, as shown in the Using LiveBinding Programatically tutorial. For more information regarding the
#pragma explicit_rtti methods()directive, please refer to the Pragma explicit rtti help topic.
Synchronizing Data through LiveBindings
Using LiveBindings in RAD Studio you can synchronize various data for instance a list box control with a string grid, provided that both contain the same data. Refer to the Synchronizing Data through LiveBindings topic in order to learn how to synchronize data through the Synch and * properties of certain components within the LiveBindings Designer.
Creating LiveBindings-Enabled Components
There are two requirements to enable a simple control like TTrackBar for LiveBindings usage. The first requirement is that the control must implement observer support. LiveBindings depends on observers to subscribe to control notifications. The second requirement is to register the control value name (for instance:
Position for a TTrackBar component). The control value name is used by LiveBindings components to generate expressions which get and set the control’s value.
For more information on how to create LiveBindings-enabled components, read the Creating LiveBindings-Enabled Components tutorial.
- LiveBindings Designer
- Creating LiveBindings
- LiveBindings Wizard
- LiveBindings Methods dialog box
- The Output Converters dialog box
- The LiveBindings Expression Result dialog box
- The LiveBindings Columns Editor dialog box
- New LiveBinding
- Synchronizing Data through LiveBindings
- Bindings Lists
- Binding Expression Editor
- LiveBindings and Action Lists
- Object Inspector
- New Console Application (C++)
- VCL Forms Application
- HD FireMonkey Application
- iOS Code Snippets
- Tutorial: Using LiveBinding in VCL Applications
- Tutorial: Using LiveBindings in FireMonkey Applications
- Tutorial: Using LiveBinding to Create a FireMonkey Application Without Code
- Tutorial: Using LiveBinding Programatically
- Tutorial: Linking Controls via LiveBindings Designer
- Tutorial: Using TPrototypeBindSource and the LiveBindings Designer
- Tutorial: Using LiveBindings and DataModules with the Metropolis UI
- Tutorial: Using LiveBindings to Populate a ListBox on iOS
- Tutorial: Creating LiveBindings-Enabled Components