Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Build Powerful Master-Detail Relationships With Centralized Cached Updates In Delphi

First, the CentralizedCachedUpdates sample sets up range-based master-detail relationships between datasets using two TFDQuery objects. Then, the sample shows you how to use a TFDSchemaAdapter object to enable the Centralized Cached Updates mode. To this end, the schema adapter object is used as a central change log shared by both the master and the detail datasets. Therefore, if you modify the records of both the master and the detail datasets in run time, you can apply changes for all records in the centralized change log to the database. To apply the changes, the sample implements the Apply updates button, which uses the ApplyUpdates method.

Location

You can find the CentralizedCachedUpdates sample project at:

How to Use the Sample

  1. Navigate to the location given above and open Qry_SchemaAdapter.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.
    • Modify the records of the master or the detailed datasets.
    • Click ont the Apply updates button.

Files

File in DelphiContains
Qry_SchemaAdapter.dproj
Qry_SchemaAdapter.dpr
The project itself.
fSchemaAdapter.pas
fSchemaAdapter.fmx
The main form.

Implementation

To set up a range-based master-detail relationship and a central change log, the following components have to be configured at design time using the Object Inspector as follows:

In order to set up a master-detail relationship, the SQL properties of both components have to be set up as follows:

Finally, both objects are linked in a range-based master-detail relationship, where qMaster is the master dataset and qDetail is the detail dataset. To this end, you have to set up the following properties of qDetail:

For more details you can visit the original post of Embarcadero:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDQuery.CentralizedCachedUpdates_Sample

Check out the full source code for the cached updates sample over on Embarcadero’s GitHub.

Exit mobile version