Page 1 of 1
ClientDataSet - AggregateField - Change Index
Posted: Thu 15 Aug 2013 12:57
by RonBrisola
I'm using a ClientDataSet and need to show the sum of all records of a table with an aggregate field.
When the ClientDataSet is opened the value of the aggregate field is correct. However, the user can change the IndexFieldName to sort the grid.
When this happens the value of the aggregate field appears doubled.
This is the configuration of the aggregate field:
Code: Select all
wwClientDataSetExtratoSumCalcVALMOVTO.Active := True;
wwClientDataSetExtratoSumCalcVALMOVTO.IndexName := '';
wwClientDataSetExtratoSumCalcVALMOVTO.GroupingLevel := 0;
What can I do to avoid this?
Re: ClientDataSet - AggregateField - Change Index
Posted: Fri 16 Aug 2013 06:01
by AndreyZ
I have checked this question in Delphi 2010. There is no problem with aggregate field values when changing the IndexFieldName property.
Please note that functionality of aggregate fields in TClientDataSet does not depend on used dbExpress driver. You can check if this problem occurs with the standard dbExpress driver for SQL Server that is supplied with Delphi.
Re: ClientDataSet - AggregateField - Change Index
Posted: Fri 16 Aug 2013 13:25
by RonBrisola
Thanks for the reply Andrey.
I was wary of that the problem is not with the dbExpress driver.
I was just trying to see if I could find some tip here.
Thanks
Ronaldo.
Re: ClientDataSet - AggregateField - Change Index
Posted: Fri 16 Aug 2013 13:53
by AndreyZ
I checked this question in Delphi XE2 (which I understand you are using). I still cannot reproduce this problem. Please try creating a small sample to demonstrate the problem and send it to andreyz*devart*com, including the script to create your table. Without this sample I will not be able to investigate the problem and give you a valid answer.
Re: ClientDataSet - AggregateField - Change Index
Posted: Mon 19 Aug 2013 14:14
by RonBrisola
Thanks AndreyZ.
I was creating a sample to send to you, and I think I figured out what the problem is.
If the ClientDataSet is opened with an IndexFieldName already set and different from the index of aggregate field the problem occurs.
If the index is set after the clientdataset is opened then the Sum of aggregate field is correct.
If you are still unable to reproduce this problem, please let me know, I'll send you my
sample.
Thank you very much for your help.
Re: ClientDataSet - AggregateField - Change Index
Posted: Tue 20 Aug 2013 07:50
by AndreyZ
We have investigated this problem. The problem occurs because of a bug in the TCustomClientDataSet.SetIndex method that is declared in the DBClient unit. To solve this problem, the following code:
Code: Select all
...
if FAggregatesActive then
begin
FAggFieldsInit := False;
ResetAllAggs(FAggregatesActive);
...
must be changed to the following code:
Code: Select all
...
if FAggregatesActive then
begin
CloseAggs;
ResetAllAggs(FAggregatesActive);
...
We do not claim that this is the most correct way to solve the problem. You should report this bug in Embarcadero QualityCentral at
http://qc.embarcadero.com . Please note that this bug is still present in the latest Delphi XE4.