| Master-detail relationships ADO and Delphi | |||||||||||||||||||||
| Page 3: Master-detail with AdoExpress components and Delphi | |||||||||||||||||||||
Setting up Master/Detail with ADOExpress
1. Select the ADO page on the Component palette. Add two TADOTable components and one TADOConnection to a form. If you, at this moment, set the Active property of both ADOTable components to true, you'll notice that the entire Orders table is displayed - this is because we haven't set up the master-detail relationship yet.
Your form should look something like:
![]() MasterSource and MasterFields
In our case, first, set ADOTable2.MasterSource to be DataSource1. Second, activate the Field Link Designer window to set the MasterFields property: in the Detail Fields list box and the Master Fields list box select the CustNo field. Click Add and OK. These properties keep both tables in synchronization, so as you move through the Customers table, the Orders table will only move to records which match the key field (CustNo) in the Customers table. Each time you highlight a row and select a new customer, the second grid displays only the orders pertaining to that customer. When you delete a record in a master table - all the corresponding record in the detail table are deleted. When you change a linked field in a record in a master table - the corresponding field in the detail table gets changed to (in as many records as needed). Simple as that! Stop. Note that creating a master-detail form with Delphi is not enough to support referential integrity features on two tables. Even though we can use methods described here to display two tables in a parent-child relation; if those two tables are not linked (one-to-many) within MS Access - cascading updates and deletes won't take place if you try to delete or update the "master" record.
ADO Shaping For an example of the SHAPE command take a look at the shapedemo project that shiped with Delphi (in the Demos\Ado directory). You must specify the shaping provider in your connection string, by adding Provider=MSDataShape; to the beginning. SHAPE {select * from customer} Although it takes some time to master the SHAPE command that's used to create these queries, it can result in significantly smaller resultsets. Data shaping reduces the amount of traffic crossing a network, provides more flexibility when using aggregate functions, and reduces overhead when interfacing with leading-edge tools like XML. To the next chapter First page > Intro to master-detail relations > Page 1, 2, 3 DB Course Next Chapter >> |
|||||||||||||||||||||


To create a master-detail relationships with Delphi, you simply need to set the detail table's MasterSource property to the DataSource of the master table and its MasterFields property to the chosen key field in the master table.
