FireDAC.IFDPhysCommand.FetchTables Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the Phys Layer command interface of FireDAC to fetch data from a database.


You can find the FetchTables sample project at:

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


The FetchTables sample shows you how to use the Fetch property of the IFDPhysCommand interace. The sample uses the IFDPhysCommand interace to fetch rows from the current command cursor in the DatS table. To this end, the sample creates a command interface to:

  • Prepare a SELECT command.
  • Define the structure of the DatS table.
  • Open the command interface.
  • Fetch the table.
  • Print the fetched rows

How to Use the Sample

  1. Navigate to the location given above and open FetchTables.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.


File in Delphi Contains


The project itself.


The main form.


When you run the application, you see the following components that are configured on run time:

  • A TComboBox object labeled as Use Connection Definition.
    When you click the Use Connection Definition combo box, the menu shows all the persistent connections defined on the file C:\Users\Public\Documents\Embarcadero\Studio\FireDAC\FDConnectionDefs.ini. Select an option in order to define a connection to a database. When the connection is defined, the sample uses the CreateCommand method of IFDPhysConnection to create a command interface. Then, the sample use some methods of this command interface to fetch rows from a table. Finally, the sample displays the fetched data using a TMemo object.
    To fetch data from a table, the sample implements the following steps:
    1. First, the sample uses the Prepare method in ordert to prepare the following SQL SELECT command: 'select * from {id Shippers}'.
    2. Secondly, the sample uses the Define method in order to define the structure of the DatS table.
    3. Thirdly, the sample calls the Open method to open the command interface created by the CreateCommand method of IFDPhysConnection.
    4. Finally, the sample calls the Fetch method in order to fetch rows from the DatS table.
  • A TMemo object named Console.
    The sample uses this object to display the data fetched from the table.


See Also