Using Nested Detail Tables

From RAD Studio
Jump to: navigation, search

Go Up to Creating Master-Detail Relationships

A nested table is a detail dataset that is the value of a single dataset field in another (master) dataset. For datasets that represent server data, a nested detail dataset can only be used for a dataset field on the server. TClientDataSet components do not represent server data, but they can also contain dataset fields if you create a dataset for them that contains nested details, or if they receive data from a provider that is linked to the master table of a master/detail relationship.

Note: For TClientDataSet, using nested detail sets is necessary if you want to apply updates from master and detail tables to a database server.

To use nested detail sets, the Data.DB.TDataSet.ObjectView property of the master dataset must be True. When your table type dataset contains nested detail datasets, TDBGrid provides support for displaying the nested details in a popup window. For more information on how this works, see Working with Dataset Fields.

Alternately, you can display and edit detail datasets in data-aware controls by using a separate dataset component for the detail set. At design time, create persistent fields for the fields in your (master) dataset, using the Fields Editor: right click the master dataset and choose Fields Editor. Add a new persistent field to your dataset by right-clicking and choosing Add Fields. Define your new field with type DataSet Field. In the Fields Editor, define the structure of the detail table. You must also add persistent fields for any other fields used in your master dataset.

The dataset component for the detail table is a dataset descendant of a type allowed by the master table. TTable components only allow TNestedDataSet components as nested datasets. TSQLTable components allow other TSQLTable components. TClientDataset components allow other client datasets. Choose a dataset of the appropriate type from the Tool palette and add it to your form or data module. Set this detail dataset's DataSetField property to the persistent DataSet field in the master dataset. Finally, place a data source component on the form or data module and set its DataSet property to the detail dataset. Data-aware controls can use this data source to access the data in the detail set.

See Also