A table type dataset's MasterSource and MasterFields properties can be used to establish one-to-many relationships between two datasets.
The MasterSource property is used to specify a data source from which the table gets data from the master table. This data source can be linked to any type of dataset. For instance, by specifying a query's data source in this property, you can link a client dataset as the detail of the query, so that the client dataset tracks events occurring in the query.
The dataset is linked to the master table based on its current index. Before you specify the fields in the master dataset that are tracked by the detail dataset, first specify the index in the detail dataset that starts with the corresponding fields. You can use either the IndexName or the IndexFieldNames property.
Once you specify the index to use, use the MasterFields property to indicate the column(s) in the master dataset that correspond to the index fields in the detail table. To link datasets on multiple column names, separate field names with semicolons:
Parts.MasterFields := 'OrderNo;ItemNo';
Parts->MasterFields = "OrderNo;ItemNo";
To help create meaningful links between two datasets, you can use the Field Link designer. To use the Field Link designer, double click on the MasterFields property in the Object Inspector after you have assigned a MasterSource and an index.
The following steps create a simple form in which a user can scroll through customer records and display all orders for the current customer. The master table is the CustomersTable table, and the detail table is OrdersTable. The example uses the BDE-based TTable component, but you can use the same methods to link any table type datasets.
Component |
Property |
First TTable |
DatabaseName: DBDEMOS TableName: CUSTOMER Name: CustomersTable |
Second TTable |
DatabaseName: DBDEMOS TableName: ORDERS Name: OrdersTable |
First TDataSource |
Name: CustSource DataSet: CustomersTable |
Second TDataSource |
Name: OrdersSource DataSet: OrdersTable |
MasterSource
MasterSource
MasterSource
MasterSource
MasterFields
MasterFields
MasterFields
MasterFields
MasterFields
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|