Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Secrets Of FireDAC: Learn How To Use Macros In TFDQuery With This Delphi Sample

The Macros sample shows you how to use the Macros property of TFDQuery in order to parameterize parts of the SQL query. The sample allows you to modify the macro values at run time.

Location

You can find the Macros sample project at:

How to Use the Sample

  1. Navigate to the location given above and open 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 Macros values.
    • Click on the Open Query button.

Files

File in DelphiContains
Macros.dproj
Macros.dpr
The project itself.
fMacros.pas
fMacros.fmx
The main form.

Implementation

Before running the sample, the main components are configured at design time using the Object Inspector as follows:

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 sample enables the Open Query button. Then, if you click on the Open Query button, the sample uses the Open method of qryMain in order to execute the SQL statement. The SQL statement is executed using the Macros values in order to retrieve the corresponding data, which is displayed using a TDBGrid component. Once the DBGrid1 is filled, you can interact with the sample in run time:

Please follow the link below to get more information about the sample:

http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.TFDQuery.Macros_Sample

Exit mobile version