TAggregateField not calculated when Index of ClientDataset changes

泄露秘密 提交于 2019-12-06 11:14:31

问题


I am using a TClientDataset, connected to a DBGrid, with a couple of Aggregate Fields, for calculating the SUM of an other couple of Float Fields. All fields have been created in Design time.

Everything is working as expected, until the time that the IndexName of the ClientDataset changes with a custom Index, in order to sort the Grid. After that, the Aggregate Fields don't calculate their value properly, and they are set with Null value.

The problem occurs in Delphi XE7.


回答1:


I have google about it and i found a solution that worked for me here

There is a bug at TCustomClientDataSet.SetIndex method that is declared in the DBClient unit. The solution propose to replace the following code

if FAggregatesActive then
begin
    FAggFieldsInit := False;
    ResetAllAggs(FAggregatesActive);

with the next one

if FAggregatesActive then
begin
    CloseAggs;
    ResetAllAggs(FAggregatesActive);

As far as i understand, the replacement of FAggFieldsInit := False with CloseAggs, force the Aggregates to be released and then recalculate with the new index. As i said this solution worked for me, and i haven't notice any unwanted behavior.

The credit goes to AndreyZ for the original solution.



来源:https://stackoverflow.com/questions/48888172/taggregatefield-not-calculated-when-index-of-clientdataset-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!