FireDAC.IFDPhysCommand.Macros Sample

From RAD Studio Code Examples
Jump to: navigation, search

This sample demonstrates how to use the Macros property of IFDPhysCommand.


You can find the Macros sample project at:

  • Start | Programs | Embarcadero RAD Studio Alexandria | Samples and then navigate to:
    • Object Pascal\Database\FireDAC\Samples\Phys Layer\IFDPhysCommand\Macros
  • 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 Macros sample shows you how to use the Macros property of IFDPhysCommand in order to parameterize parts of the SQL query. The sample allows you to modify the macro values at run time.

Note: See the Preprocessing Command Text topic for more information about parameterizing SQL command texts.

How to Use the Sample

  1. Navigate to the location given above and open IFDPhys_Macros.dproj.
  2. Press F9 or choose Run > Run.
  3. Click on the Use Connection Definition combo box and select an option.
  4. Interact with the sample:
    • Modify the values of the Macros to retrieve the desired data. For example, change 'Address' to 'First Name'.
    • Click the Fetch button and see the retrieved data.


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 sets up five Macros that are used on the SQL statement: COLUMN, TAB, ID, Sign, IDVALUE. Finally, the sample fills the lstMacros list editor with the predefined Macros and enables the lstMacros, Data type and Fetch objects.
  • A TValueListEditor object named lstMacros.
    The sample use this object to show and modify the list of Macros. Modify the value of any Macro to modify the SQL query. For example, change 'Address' to 'First Name' and click the fetch button. The information that retrieves the SQL query is different.
  • A TComboBox object labeled as Data type.
    This object allows you to change the data type of the selected Macros value.
  • A Tbutton object called Fetch.
    Click the Fetch button to retrieve the desired data using the defined Macros and the following SQL command text: 'select !column from !tab where (!id !Sign !idValue)'. To this end, the sample uses the Prepare, Define, Open and Fetch methods of the command interface created before.
  • A TMemo object named mmSQL.
    The sample uses this object to show the SQL command text.
  • A TMemo object named Console.
    The sample uses this object to display the retrieved data from the SELECT statement.


See Also