API:FireDAC.Comp.Client.TFDCommand.Macros

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property Macros;

C++

__property Macros;

Properties

Type Visibility Source Unit Parent
property published
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCommand

Description

The collection of a macro's substitution variables.

FireDAC.Comp.Client.TFDCommand.Macros inherits from FireDAC.Comp.Client.TFDCustomCommand.Macros. All content below this line refers to FireDAC.Comp.Client.TFDCustomCommand.Macros.

The collection of a macro's substitution variables.

The Macros property is the collection of a macro's substitution variables. It is populated automatically after assigning CommandText, if ResourceOptions.MacroCreate is True. Otherwise it may be populated manually.

When calling Prepare, the macro values are substituted into CommandText, if ResourceOptions.MacroExpand is True.

Example

//Example 1 - Substitute table name:
ADCommand1.CommandText.Text := 'select * from &Tab';
ADCommand1.Macros[0].AsIdentifier := 'Order Details';
ADCommand1.Prepare;
ShowMessage(ADCommand1.SQLText); // select * from "Order Details"

//Example 2 - Substitute WHERE condition:
ADCommand1.CommandText.Text := 'select * from MyTab {if !cond} where !cond {fi}';
ADCommand1.Macros[0].AsString := 'ID > 100';
ADCommand1.Prepare;
ShowMessage(ADCommand1.SQLText); // select * from MyTab where ID > 100
ADCommand1.Macros[0].Clear;
ADCommand1.Prepare;
ShowMessage(ADCommand1.SQLText); // select * from MyTab

See Also