procedure TForm1.Button3Click(Sender: TObject);
var
i, BeforeFilter, WithFilter, AfterFilter:integer;
begin
//Clear the existing field defs and aggregates
with TClientDataset.Create(nil) do
try
//Add FieldDef
with FieldDefs.AddFieldDef do
begin
Name := 'Field1';
DataType := ftInteger;
end;
//Add an aggregate summing Field1
with Aggregates.Add do
begin
AggregateName := 'SumField1';
Expression := 'SUM(Field1)';
Active := true;
end;
AggregatesActive := true;
//Create and populate the Dataset
CreateDataset;
for i := 1 to 10 do
AppendRecord([i]);
//Aggregate before the filter applied (55)
BeforeFilter := Aggregates.Find('SumField1').Value;
//Aggregate with filter applied (10)
Filter := 'Field1 < 5';
Filtered := true;
WithFilter := Aggregates.Find('SumField1').Value;
//Aggregate after filter removed (should be 55, but returns 65).
Appears to
//be Aggregate with no filter + Aggregate with last filter
Filter := '';
Filtered := false;
AfterFilter := Aggregates.Find('SumField1').Value;
//Needed so we don't get 'Operation Not Applicable' error on close,
but
//thats another story :-)
AggregatesActive := false;
Aggregates.Clear;
Close;
ShowMessageFmt('Before:%d, Filtered:%d, After:%d',[BeforeFilter,
WithFilter, AfterFilter])
finally
Free;
end;
end;
Is this a known bug, or is it something to do with my code? Has anyone
else encountered this and know of a work around?
--
Cheers,
David Clegg
dclegg_at_ebetonline_dot_com.