Linking a Control with a Field

From RAD Studio
Jump to: navigation, search

Go Up to LiveBindings Wizard


This procedure shows you how to link a control with a field in a dataset, by means of the LiveBindings Wizard.

Start by creating an HD Multi-Device Application. Then place a label and a client dataset on the form. You bind the label control to a text field in the data file that is passed to the dataset.

For this procedure to work, you need to have the biolife.cds database, which is typically installed in \Data of the Samples at Start | Programs | Embarcadero RAD Studio Sydney | Samples. Biolife.cds is also available with the Samples on GitHub Repositories. A code example that uses a similar database (DBDEMOS) is described in FishFacts (Delphi). Note that the biolife.fds database is a FireDAC database that might require different steps. A LiveBindings tutorial is also available here: Tutorial: Using LiveBindings to Create an Application Without Code.

Tip: In order for the LiveBindings Wizard to be available in the right-click context menu, you need to enable it in Tools > Options > LiveBindings by selecting "Display LiveBindings Wizard in right-click menu". (If you start the wizard from the LiveBindings Designer, then you do not need to enable the wizard command in the options dialog box.)


Step 1: Binding Task

After placing the label control on the form, you need to bind it to the Name field in the dataset.

First click the client dataset component and, in the Object Inspector, locate the FileName property. Specify the location of the biolife.cds database.

Locate the Active property in the Object Inspector and set it to True.

Right-click the label control and select the LiveBindings Wizard command.

Then select Link control "Label1" with a field from the Binding Task wizard page.

LBTLinkControlWithField1.png

Validate your selection by clicking the Next button.

Step 2: Data Source

Here you need to select the dataset on the Existing Source tab.

LBTLinkControlWithField2.png

Validate your selection by proceeding to the next step.

Step 3: Field

Now you are presented with a list of available fields in the biolife.cds database. Select the Category field.

LBTLinkControlWithField3.png

Click Next.

Step 4: Options

You are prompted whether you want a data source navigator to be created along with your binding expression.

Choose to add a data source navigator for this example.

LBTLinkControlWithField4.png

Click Finish, as this is the last page of the wizard.

After the wizard closes, a new binding expression is created that binds the label control and the Category field in the specified dataset.

The Results

After the wizard closes and you are returned to the designer in the IDE, you can see that two new LiveBindings engine-related components have been added (TBindingsList, and TBindScopeDB) and a TBindNavigator component. To bring up the Binding Expression Editor dialog box, double-click the BindingsList1 component.

LBTLinkControlWithFieldBindingsList.png

Now run the application (press F9) and test your binding expression by cycling through the records in the dataset. You should see that the label updates correctly.

A screenshot of the running application is shown below.

LBTLinkControlWithFieldResults.png

See Also