Subject Re: [IBO] Re: MacroSubstitute
Author Markus Ostenried
At 18:26 Tuesday, 27.01.2004 +0000, you wrote:
>There are no "macro" substitutes,

not quite true: look up TIB_Query.OnMacroSubstitute event and
TIB_Statement.MacroBegin and MacroEnd properties in the IBObjects help file.
MacroBegin and MacroEnd can also be set globally for a TIB_Connection
object, defaults are << (begin) and >> (end).

>but you can use

that's right and you should always try to do it this way first because it
is much faster to assign a different parameter value to an already prepared
statement than to prepare the stament again.
Qry.SQL.Add( 'C.DATA_VCTO BETWEEN :p1 AND :p2' );
Qry.ParamByName( 'p1' ).AsInteger := DATA_INICIAL;
Qry.ParamByName( 'p2' ).AsInteger := DATA_FINAL;

if you have to assign different where clauses to your query then have a
look at the OnPrepareSQL event. This event is called every time the stament
needs to be prepared. You can add your custom criteria in this event, like

procedure TForm1.qryDespesasDiasPrepareSQL(Sender: TIB_Statement);
if Trim(Pagas) <> '' then begin
{ no 'AND' needed below because every line you add here will be
preceeded by an AND automatically. If you don't want this then insert an
'OR' in the beginning of the string. Assignements to the SQLWhereItems
property are only valid in this event and you can't rely on its contents
outside of this event handler }
qryDespesasDias.SQLWhereItems.Add(' PAGAS= 0');

in a ButtonClick event you can do something like this:

{ tell the query that it has to re-prepare itself the next time it is used }
{ force immediate refresh: this will cause the query to re-prepare and
thus call the OnPrepareSQL event }