This sample demonstrates how to use the main functionalities of the TFDMemTable class.
You can find the Main sample project at:
- Start | Programs | Embarcadero RAD Studio 10.2 Tokyo | Samples and then navigate to:
Object Pascal\Database\FireDAC\Samples\Comp Layer\TFDMemTable\Main
- Subversion Repository:
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
- Navigate to the location given above and open
- Press F9 or choose Run > Run.
|File in Delphi||Contains|
The project itself.
The main form.
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:
- A TFDTable object named FDTable1
- This component is used to browse a database table and edit its records. To this end, the ConnectionName property is set to
SQLite_Demousing the Object Inspector at design time.
- A TFDMemTable object named MT.
- 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.
- A TDataSource object named DataSource1.
- 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
MTand 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:
- 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.
- The Reset button sets the Active property of MT to
Falseand 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.
- This tab shows the lists of all non-aggregate field components of the dataset. Moreover, the tab implements other functionalities related to the fields.
- 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.
- The sample implements this tab to Add, Delete or Modify aggregate fields to the collection of client-side aggregates defined for the dataset.
- 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.
- 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.
- 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
AKeepSettingsparameters of CloneCursor.
- Working with DataSets (FireDAC)
- Working with Field Component Methods at Runtime
- Displaying, Converting, and Accessing Field Values
- Displaying and Editing a Subset of Data Using Filters
- Cloning a Client Dataset Cursor
- TFDMemTable Questions