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.
Table of Contents
Location
You can find the Macros sample project at:
- Start | Programs | Embarcadero RAD Studio Sydney | Samples and then navigate to:
Object PascalDatabaseFireDACSamplesPhys LayerIFDPhysCommandMacros
- 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
IFDPhys_Macros.dproj
. - Press F9 or choose Run > Run.
- Click on the Use Connection Definition combo box and select an option.
- 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.
- Modify the values of the Macros to retrieve the desired data. For example, change
Files
File in Delphi | Contains |
---|---|
IFDPhys_Macros.dproj IFDPhys_Macros.dpr | The project itself. |
fMacros.pas fMacros.fmx | The main form. |
Implementation
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:UsersPublicDocumentsEmbarcaderoStudioFireDACFDConnectionDefs.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.
Fore more information you can follow the link below:
http://docwiki.embarcadero.com/CodeExamples/Sydney/en/FireDAC.IFDPhysCommand.Macros_Sample
Head over and check out the full source code for the FireDAC macros sample on Embarcadero’s GitHub.
Design. Code. Compile. Deploy.
Start Free Trial Upgrade Today
Free Delphi Community Edition Free C++Builder Community Edition