ClientDataSet - AggregateField - Change Index

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
RonBrisola
Posts: 14
Joined: Wed 14 Nov 2012 12:59

ClientDataSet - AggregateField - Change Index

Post by RonBrisola » Thu 15 Aug 2013 12:57

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?

AndreyZ

Re: ClientDataSet - AggregateField - Change Index

Post by AndreyZ » Fri 16 Aug 2013 06:01

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.

RonBrisola
Posts: 14
Joined: Wed 14 Nov 2012 12:59

Re: ClientDataSet - AggregateField - Change Index

Post by RonBrisola » Fri 16 Aug 2013 13:25

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.

AndreyZ

Re: ClientDataSet - AggregateField - Change Index

Post by AndreyZ » Fri 16 Aug 2013 13:53

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.

RonBrisola
Posts: 14
Joined: Wed 14 Nov 2012 12:59

Re: ClientDataSet - AggregateField - Change Index

Post by RonBrisola » Mon 19 Aug 2013 14:14

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.

AndreyZ

Re: ClientDataSet - AggregateField - Change Index

Post by AndreyZ » Tue 20 Aug 2013 07:50

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.

Post Reply