The CloneCursor sample shows you how to clone a dataset. To this end, the sample uses the CloneCursor method of the TFDDataSet class. Moreover, the sample uses other methods to determine whether the current record is within a specified range.
Table of Contents
Location
You can find the CloneCursor sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesComp LayerTFDMemTableCloneCursor
- Subversion Repository:
- You can find Delphi code samples in GitHub Repositories. Search by name into the samples repositories according to your RAD Studio version.
How to Use the Sample
- Navigate to the location given above and open
CDS_CachedUpdates.dproj
. - Press F9 or choose Run > Run.
- Click on the Use Connection Definition combo box and select an option.
- Click on the CloneCursor button to clone the dataset.
- Modify the Start range (OrderID) and End range (OrderID) labels.
- Click on the CheckRange button.
Files
File in Delphi | Contains |
---|---|
CDS_CachedUpdates.dproj CDS_CachedUpdates.dpr | The project itself. |
fCachedUpdates.pas fCachedUpdates.fmx | The main form. |
Implementation
This sample uses three main components:
- TFDCommand. It uses TFDConnection to connect to the desired database. In the commandText property of TFDCommand there is a SQL command for selecting data from database:
select * from {id Orders}
. You can check it on the Object Inspector. - TFDTableAdapter. It provides communication between the application and the database. It is a mediator between TFDCommand and TFDMemTable.
- TFDMemTable. It retrieves data from database through TFDTableAdapter and TFDCommand. The sample uses two TFDMemTable: one for the original dataset, which is named cdsOrders and the other for the cloned dataset, which is named cdsClone.
When you run the application, click on the Use Connection Definition combo box and select an option in order to define a connection. When you select an item of the combo box, the Active property of the cdsOrders table is set to True
in order to open the dataset and read data from the database. Then, the sample displays a table using a TDBGrid component. Once the TDBGrid is filled, you can interact with the sample. Each of the following buttons implements an OnClick event to do what is described below:
- When you click on the CloneCursor button, the sample clones the cdsOrders table using the CloneCursor method and sets the Active property of the cdsClone table to
True
in order to populate the table with the cloned data. - When you click on the CheckRange button, the sample uses the Start range (OrderID) and End range (OrderID) labels as the starting and ending values of the SetRange method. Then the sample applies the range to the cdsClone table using the GotoCurrent method.
- When you click on the CancelRange button, the sample uses the CancelRange to remove the current range.
Please refer to the next links for the source code of this Sample:
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition