Subject Re: [IBO] SQLWhereItems.Add only inside OnPrepare?
Author Joseph Alba
Actually you can do this by:

Button1.Click()
Data.Condition1 := whatever;

Button2.Click()
Data.Condition2 := whatever

Button3.Click()
Data.Condition3 := whatever.

---
declare condition1 to condition3 as properties of the Datamodule (Data)

private
FCondition1: Sometype;
FCondition2: SomeType,
...
procedure SetCondition1( Value: SomeType);
...
public
property Condition1: Sometype read FCondition1 write SetCondition1;
....


property TData.SetCondition1(Value: SomeType);
begin
FCondition1 := Value;
Query.InvalidateSQL;
Query.Refresh;
// first may be omitted
end;

procedure .. OnPrepareSQL
begin
if FCondition1 = SomeValue then
SQLWhereItems.Add('SomeCondition1=SomeValueOrSomething');
if FCondition2=SomeValue2 then
SQLWhereItems.Add('...');
end;

Moral Lesson:
In Object-Oriented Programming, remember to pass messages to Objects and
let the Objects take care of the processing.

Joseph Alba
jalba@...




mmenaz@... wrote:

> Hi, I'm using SQLWhereItems to change query conditions at runtime.
> After some experiments, I've found that the only place where put the
> SQLWhereItems.Add('condition') is in the OnPrepare event of the query.
> So my program has a button that, once pressed, does:
> InvalidateSQL;
> Refresh;
> First;
> and in the OnPrepare are set the query SQL conditions.
>
> It would useful to me if, instead, would be possible to set these
> conditions outside the OnPrepare, so I could have, for instance, 3
> buttons with different conditions, or programmatically use different
> conditions in the program flow without the need of a global variable
> to make OnPrepare aware of what condition I need. Is it possible? I
> mean something like:
> Button1.Click()
> begin
> InvalidateSQL;
> SQLWhereItems.Add('condition1')
> SQLWhereItems.Add('condition2')
> Refresh;
> First;
> end;
>
> Thanks
>
> Marco Menardi
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/