Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
C++IDERAD Studio

Quickly Bind Your Data Source To Different Types Of Data With LiveBindings Delphi AdapterBindSource Sample App

LiveBindings help Delphi/C++ developers to connect source and control component with no lines of code. Connecting to the Datasource or TPrototypeBindSource is straightforward way to connect to your controls. How about binding the custom data collections created for your application with your control components? No Idea ? Don’t worry. This post can guide you to do the job smoothly. TAdapterBindsource which supports adapters to connect to different types of data.

AdapterBindSource sample shows using the TAdapterBindSource to create a bidirectional binding between a generic TObjectList of user defined objects and a grid.

You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Components used in the Sample App:

  • TAdapterBindSource to provide custom data to a grid at run time.
  • TDataGeneratorAdapter It is used to generate some prototype data for design time purposes. It is replaced at runtime with the user defined data. It is optional and is only used for design time.

The grid and the adapters are linked using LiveBindings.

Implementation details :

Design Time:

  • The Adapter property of the TAdapterBindSource is filled at design time with the TDataGeneratorAdapter to generate some prototype data.
  • Three FieldDefs items are added to the TDataGeneratorAdapter using the Fields Editor.
  • The sample uses LiveBindings to create the binding between the adapter and the grid.

Run Time : At run time, the TDataGeneratorAdapter is replaced with the user-defined data.

  • CollectionObjects.pas contains a custom class, TPerson, that contains three properties: FirstNameLastName and Age.
  • The OnCreateAdapter event of the TAdapterBindSource is used to initialize a user defined list. The list is a TObjectList that contains individual TPerson objects.
  • After creating the list, the collection is populated with hard-coded data provided in ABSMain.pas.
  • An adapter ( TBindSourceAdapter) provides the data to the grid. It uses TListBindSourceAdapter to implement the adapter for the user-defined list of objects.
  • LiveBindings creates the binding between the adapter and the grid.

JSON Data : The sample uses the OnChange event from the TTabControl to populate the TMemo from the JSON tab with the JSON representation of the data from the grid. Making changes on the Grid data, updates the data from the JSON tab, and vice versa. Check out the full article in the DocWiki about the LiveBindings.AdapterBindSource Sample.

<strong>AdapterBindSource Sample App<strong>

Check out the full source code for the AdapterBindSource projects for Delphi and C++Builder over on GitHub.

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

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

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES