LiveBindings.AdapterBindSource Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample project demonstrates the use of a TAdapterBindSource.

Location

You can find the AdapterBindSource sample project at:

Description

This sample demonstrates the use of TAdapterBindSource and TDataGeneratorAdapter.

The grid and the adapters are linked using LiveBindings.

The sample also uses LiveBindings to bind a TBindNavigator with a TGrid.

How to Use the Sample

  1. Navigate to the location above and open AdapterBindSourceSample.dproj.
  2. Press F9 or choose Run > Run.
  3. When you run the application, the TGrid is populated with a user-defined list.
    1. Use the TBindNavigator to navigate through the rows and to add/delete items at run time.
      Note: The modifications to the fields remain only at run time.
  4. Go to the JSON tab to see a JSON representation of the data.
  5. Any modification over the data in the Grid or JSON tab applies to the other tab at run time.

Files

File Contains

AdapterBindSourceSample.dproj

The project itself.

ABSMain.fmx / pas

The main form and main unit.

CollectionObjects.pas

The unit with the definition of the custom class TPerson.

ABSMain.iPhone4in.fmx / ABSMain.LgXhdpiPh.fmx

View forms for iPhone and Android.

Implementation

At 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.

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

At Run Time

CollectionObjects.pas contains a custom class, TPerson, that contains three properties: FirstName, LastName 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 Tab

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.

Uses

See Also