FireDAC.Comp.Client.TFDCustomCommand.Macros

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property Macros: TFDMacros read FMacros write SetMacros stored False;

C++

__property Firedac::Stan::Param::TFDMacros* Macros = {read=FMacros, write=SetMacros, stored=false};

Properties

Type Visibility Source Unit Parent
property public
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDCustomCommand

Description

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