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

Quickly Set Up Flexible Master-Detail Relationships Between Datasets In Delphi Apps

The sample 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, the sample uses the Mode property of TFDFetchOptions to control how the result set records must be fetched into the FireDAC internal data storage.

Location

You can find the MasterDetail sample project at:

How to Use the Sample

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

Files

File in DelphiContains
CDS_MasterDetail.dproj
CDS_MasterDetail.dpr
The project itself.
fMasterDetail.pas
fMasterDetail.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:

Both objects uses TFDConnection to connect to the desired database. Moreover, both TFDCommand objects use their CommandText property to write a SQL command to select data from a database. In order to set up a master-detail relationship, both CommandText properties have to be set up using the Object Inspector at design time as follows:

This component provides communication between the application and the database. The TFDTableAdapter object is a mediator between TFDCommand and TFDMemTable. To this end, the SelectCommand property of adOrders is set to cmOrders while the SelectCommand property of adOrderDetails is set to cmOrderDetails.

This component retrieves data from database through TFDTableAdapter and TFDCommand. To this end, the Adapter property of cdsOrders is set to adOrders while the Adapter property of cdsOrdDetails is set to adOrderDetails.

This component provides an interface between a dataset component and data-aware controls on a form. In this sample, it is used to provide communication between the datasets and the grids where the datasets are displayed. To this end, the following properties are set up at design time using the Object Inspector:

For more information please refer to the link below:

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

Check out the full source code for the master detail app built in Delphi and FireDAC.

Exit mobile version