FireDAC.TFDMemTable.Main Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the main functionalities of the TFDMemTable class.

Location

You can find the Main sample project at:

  • Start | Programs | Embarcadero RAD Studio Rio | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDMemTable\Main
  • Subversion Repository:
    • You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.

Description

The Main sample shows you how to use different database functionalities related with the TFDMemTable class. To this end, the sample uses different properties and methods of the cited class. The following dataset features are implemented:

  • Save a dataset data to a file.
  • Load a dataset data from a file.
  • Modify the fields and the indexes of the fields in a dataset.
  • Define the client-side aggregating formulas.
  • Filter a dataset to search for specific records.
  • Set the beginning and ending range values for the dataset and apply the range.
  • Clone a dataset.

How to Use the Sample

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

Files

File in Delphi Contains

CDS_main.dproj
CDS_main.dpr

The project itself.

fMainDemo.pas
fMainDemo.fmx

The main form.

Implementation

The goal of this sample is to show how to implement different functionalities related with the TFDMemTable class. To this end, the sample first configures the main components:

This component is used to browse a database table and edit its records. To this end, the ConnectionName property is set to SQLite_Demo using the Object Inspector at design time.
This component retrieves data from database through TFDTable. To this end, the sample implements a FormCreate event that uses the CopyDataSet method to copy on run time the records from FDTable1 to MT.
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 dataset and the grid where the dataset is displayed. To this end, the DataSet property of DataSource1 is set to MT and the DataSource property of DBGrid1 is set to DataSource1. This set up is done at design time using the Object Inspector.

When you run the application, you see a multiple page dialog and a table displayed on DBGrid1. The grid is used to display and manipulate records from MT. Once the grid is filled, you can interact with the sample by using the features that are implemented in each tab:

  • Content
This tab uses the following four buttons to implement some TFDMemTable features:
  • 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 Load from 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 format: binary, XML and JSON. The cited methods can work with the three file formats adding the following objects to the form: TFDStanStorageXMLLink, TFDStanStorageJSONLink and TFDStanStorageBinLink.
  • The Reset button sets the Active property of MT to False and clears the Fields, the Indexes and the Aggregates of the dataset.
  • The Get SQLite Customers button opens the FDTable1 and uses the CopyDataSet method to copy the records from FDTable1 to MT.
  • Fields
This tab shows the lists of all non-aggregate field components of the dataset. Moreover, the tab implements other functionalities related to the fields.
  • Indexes
This tab shows the list of all client indexes that apply to the dataset. Moreover, the tab uses different labels and buttons to implement other indexes related features.
  • Aggregates
The sample implements this tab to Add, Delete or Modify aggregate fields to the collection of client-side aggregates defined for the dataset.
  • Filter
This tab uses the Filter label to specify the text of the current filter for a dataset. For example: type country='Spain' in the label and then check the Active check box to see displayed only those records that meet the Country field condition.
  • Ranges
This tab implements four buttons to set and edit the starting and ending values of a range. Moreover, it also implements two more buttons to apply or clear the range. To this end the sample uses the following properties attached to the corresponding button: SetRangeStart, EditRangeStart,SetRangeEnd, EditRangeEnd, ApplyRange and CancelRange. Perform the following steps to apply a range:
  • Click on the SSt button.
  • Type the CustomerID field of the starting value of your range.
  • Click on the SEn button.
  • Type the CustomerID field of the ending value of your range.
  • Click on the Apply button.
  • Clone
The clone tab is used to clone the MT table using the CloneCursor method. Moreover, the reset and KeepSettings check boxes are used to determine the AReset and AKeepSettings parameters of CloneCursor.

Uses

See Also

Samples