AnyDAC
ContentsIndexHome
PreviousUpNext
TADCommand.Macros Property

The collection of macro substitution variables.

Group
Links

The Macros property is the collection of macro substitution variables. It is populated automatically after assigning CommandText, if ResourceOptions.MacroCreate = True. Otherwise it may be populated by hands. At Prepare call, macro values will be substituted into CommandText, if ResourceOptions.MacroExpand = True.

property Macros: TADMacros;

Substitute table name:

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

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 AnyDAC\Samples\Comp Layer\TADQuery\Macros demo for details.

What do you think about this topic? Send feedback!