Ex:
var
sFieldName :String;
fdAggregate:TAggregate;
fdAggregate:TAggregate;
begin
cdsTemp := TClientDataset.Create(Self);
cdsTemp := TClientDataset.Create(Self);
cdsTemp.Aggregates.Clear;
cdsTemp.AggregatesActive := True;
cdsTemp.CloneCursor(Master, False, True);
cdsTemp.CloneCursor(Master, False, True);
for i:=0 to Master.FieldCount-1 do
begin
sFieldName := Master.Fields[i].FieldName;
if cdsTemp.FieldByName(sFieldName).DataType in
begin
sFieldName := Master.Fields[i].FieldName;
if cdsTemp.FieldByName(sFieldName).DataType in
[ftSmallint, ftInteger, ftFloat, ftCurrency, ftLargeint] then
begin
fdAggregate := TAggregate.Create(cdsTemp.Aggregates, cdsTemp);
fdAggregate.AggregateName := 'agg' + sFieldName;
fdAggregate.Expression := 'sum('+sFieldName+')';
fdAggregate.Active := True;
end;
end;
begin
fdAggregate := TAggregate.Create(cdsTemp.Aggregates, cdsTemp);
fdAggregate.AggregateName := 'agg' + sFieldName;
fdAggregate.Expression := 'sum('+sFieldName+')';
fdAggregate.Active := True;
end;
end;
//Get Value
cdsTemp.Aggregates.Find('agg'+sFieldName).Value;
end;