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

Easily Build Master-Detail Relationships Between Datasets In Delphi Windows Apps

The sample demonstrates how to use the TFDQuery component in order to set up master-detail relationships between datasets. It uses the master-detail relationship to automatically filter a detail dataset based on a current master dataset record. In this sample, the master dataset has “Order” records, and the detail dataset shows only lines for the current order. Moreover, you can modify in run time the Cache property of TFDFetchOptions to control the data allocation in cache memory.

Location

You can find the MasterDetail sample project at:

How to Use the Sample

  1. Navigate to the location given above and open Qry_MasterDetail.dproj.
  2. Press F9 or choose Run > Run.

Files

File in DelphiContains
Qry_MasterDetail.dproj
Qry_MasterDetail.dpr
The project itself.
fQueryMasterDetail.pas
fQueryMasterDetail.fmx
The main form.

Implementation

To set up a master-detail relationship, this sample uses the Object Inspector to configure the following components at design time as follows:

In order to set up a master-detail relationship, the SQL properties of both components have to be set up using the Object Inspector at design time as follows:

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

Please refer to the link below for more information about the sample:

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

Head over and check out the full source code for the master detail Windows sample app on GitHub.

Exit mobile version