Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDatabaseDelphiRAD Studio

Easily Learn To Store Data In A Nested Dataset using FireDAC With FireDAC.TFDMemTable.NestedDataSet Sample

The NestedDataSet sample shows you how to set a nested dataset in a dataset field.


You can find the NestedDataSet sample project at:

  • Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to – Object PascalDatabaseFireDACSamplesComp LayerTFDMemTableNestedDataSet
  • Subversion Repository – You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.


To this end, the sample uses the NestedDataSet property. Moreover, the sample implements the following functionalities that are attached to three different button events:

  • Copy the dataset data to another TFDMemTable.
  • Save the dataset data to a file.
  • Read the dataset data from a file.

How to Use the Sample

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


File in DelphiContains
The project itself.
The main form.
The copied datasets form.


The goal of this sample is to demonstrate how to set nested datasets in dataset fields. To this end, the sample implements the following steps at run time:

  • The sample uses a TFDMemTable object named FDMemTable1 to implement an in-memory dataset. Therefore, FDMemTable1 manages data in the client memory. The sample defines FDMemTable1 as follows:
    1. The sample uses the AddFieldDef method to add field definitions to FDMemTable1. The sample adds three fields named: f1f2 and f3. The sample configures the f1 field with the TFieldType set to ftInteger. Moreover, the TFieldType property of f2 is set to ftString and the f3 field is set to ftDataSet, which means that this field contains a nested dataset.
    2. The sample adds two child fields to the f3 and names them as: f31 and f32. Both child fields are configured with the TFieldType set to ftInteger.
  • The sample fills FDMemTable1 using the Append method with 100 records as follows:
    1. f1 is set to integer values from 1 to 100.
    2. f2 is set to string values from qqq1 to qqq100.
    3. f3 is filled by nested datasets, each consisting of two records. The sample uses the NestedDataSet property to store data in each nested dataset.

When you run the application, you see a table displayed in a TDBGrid. The grid is used to display and manipulate records from FDMemTable1. Once the grid is filled, you can interact with the sample. Each of the following buttons implements an OnClick event to do what is described below:

  • The Save to file button uses the SaveToFile method to save the dataset data to an external file for later use by this or other datasets.
  • The Read file button uses the LoadFromFile method to populate the dataset with data stored in an external file. The data is not moved to a database, it is just loaded into a dataset in-memory storage.

Note: Both methods could work with three different file formats: binaryXML and JSON. The cited methods can work with the three file formats adding the following objects to the form: TFDStanStorageXMLLinkTFDStanStorageJSONLink and TFDStanStorageBinLink.

  • The Show copy button copies the datasets from FDMemTable1 to FDMemTable2 and uses the ShowModal property to show the copied dataset on the grid of the fNestedCopy form.

Note: The ShowModal property shows the fNestedCopy form as a modal form, which means that the application cannot continue to run until the modal form is closed.


Check out the full source code on GitHub!

Next, learn how you can append to String Python and answer other questions about String Operations in C++ software in this article.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.