In a project, using Dbgrideh, when using a self-contained memory dataset, the average value added for footers is always displayed as 0, the other summary data is available, and the switch uses TClientDataSet or Tadodataset, All summary data, including averages, have values.
Open the relevant part of the source to see the next, found that the Dbgrideh of memory data set on the summary of the average this piece, unexpectedly did not deal with ..., what situation?
Primitive correlation function:
procedureTcustommemtableeh.getaggregatedvaluesforrange (FROMBM, Tobm:tunibookmarkeh; fieldname:string; varResultarr:taggrresultarr; AGGRFUNCS:TAGGRFUNCTIONSEH);varFROMRN, Torn:integer; I:integer; V:variant; Vartypenum:integer; Fieldindex:integer;beginResultarr[agfsumeh]:=Null; Resultarr[agfcounteh]:=0; RESULTARR[AGFAVG]:=Null; Resultarr[agfmin]:=Null; Resultarr[agfmax]:=Null; if notActive ThenExit; ifFROMBM <> Nilbookmarkeh Then ifunibookmarkvalid (FROMBM) ThenFROMRN: =unibookmarktorecno (FROMBM)ElseExitElseFROMRN:=1; ifTOBM <> Nilbookmarkeh Then ifunibookmarkvalid (TOBM) ThenTorn: =unibookmarktorecno (TOBM)ElseExitElseTorn:=RecordCount; if(FieldName ="') and(Aggrfuncs = [Agfcounteh]) Then begin forI: = fromrn-1 totorn-1 DoResultarr[agfcounteh]:= Resultarr[agfcounteh] +1; Exit; End; ifFRecordsView.MemTableData.DataStruct.FindField (FieldName) =Nil ThenExit; Vartypenum:=FRecordsView.MemTableData.DataStruct.FieldByName (FieldName). Getvardatatype; Fieldindex:=FRecordsView.MemTableData.DataStruct.FieldIndex (FieldName); forI: = fromrn-1 totorn-1 Do beginV:=Frecordsview.recordview[i]. Rec.value[fieldindex, Dvvvalueeh]; if notVarisnulleh (v) Then begin if(AgfcountehinchAggrfuncs)or(AgfavginchAggrfuncs) ThenResultarr[agfcounteh]:= Resultarr[agfcounteh] +1;//when the setting is averaged, only one count accumulation is done here if(Vartypenuminch[Varsmallint, Varinteger, Varsingle, vardouble, Varcurrency,{$IFDEF eh_lib_6}Varshortint, Varword, VarInt64, Varlongword,{$ENDIF}Varbyte, Vardate]) or(Vartypenum = VARFMTBCD) Then begin if(AgfsumehinchAggrfuncs) and(Vartypenum <> vardate) Then ifVarisnulleh (Resultarr[agfsumeh]) ThenResultarr[agfsumeh]: =vElseResultarr[agfsumeh]: = Resultarr[agfsumeh] +v; ifAgfmininchAggrfuncs Then ifVarisnulleh (Resultarr[agfmin]) ThenResultarr[agfmin]:=vElse ifResultarr[agfmin] > V ThenResultarr[agfmin]:=v; ifAgfmaxinchAggrfuncs Then ifVarisnulleh (Resultarr[agfmax]) ThenResultarr[agfmax]:=vElse ifResultarr[agfmax] < V ThenResultarr[agfmax]:=v; End End; End; ifAgfmaxinchAggrfuncs Then //averaging, the triggering conditions here are agfmax .... if notVarisnulleh (Resultarr[agfsumeh]) ThenResultarr[agfavg]:= Resultarr[agfsumeh]/Resultarr[agfcounteh];//This value should be 0 because there is no summation of Agfsumeh at Agfavg.End;
Modification Method:
1. Open Memtableeh.pas
2. Find the Getaggregatedvaluesforrange function and modify it as follows:
procedureTcustommemtableeh.getaggregatedvaluesforrange (FROMBM, Tobm:tunibookmarkeh; fieldname:string; varResultarr:taggrresultarr; AGGRFUNCS:TAGGRFUNCTIONSEH);varfromrn, Torn:integer; i:integer; v:variant; Vartypenum:integer; Fieldindex:integer;beginResultarr[agfsumeh]:=Null; Resultarr[agfcounteh]:=0; RESULTARR[AGFAVG]:=Null; Resultarr[agfmin]:=Null; Resultarr[agfmax]:=Null;if notActive ThenExit;ifFROMBM <> Nilbookmarkeh Then ifunibookmarkvalid (FROMBM) ThenFROMRN: =unibookmarktorecno (FROMBM)ElseExitElseFROMRN:=1; ifTOBM <> Nilbookmarkeh Then ifunibookmarkvalid (TOBM) ThenTorn: =unibookmarktorecno (TOBM)ElseExitElseTorn:=RecordCount;if(FieldName ="') and(Aggrfuncs = [Agfcounteh]) Then begin forI: = fromrn-1 totorn-1 DoResultarr[agfcounteh]:= Resultarr[agfcounteh] +1; Exit; End; ifFRecordsView.MemTableData.DataStruct.FindField (FieldName) =Nil ThenExit; Vartypenum:=FRecordsView.MemTableData.DataStruct.FieldByName (FieldName). Getvardatatype; Fieldindex:=FRecordsView.MemTableData.DataStruct.FieldIndex (FieldName); forI: = fromrn-1 totorn-1 Do beginV:=Frecordsview.recordview[i]. Rec.value[fieldindex, Dvvvalueeh]; if notVarisnulleh (v) Then begin if(AgfcountehinchAggrfuncs)or(AgfavginchAggrfuncs) ThenResultarr[agfcounteh]:= Resultarr[agfcounteh] +1; if(Vartypenuminch[Varsmallint, Varinteger, Varsingle, vardouble, Varcurrency,{$IFDEF eh_lib_6}Varshortint, Varword, VarInt64, Varlongword,{$ENDIF}Varbyte, Vardate]) or(Vartypenum = VARFMTBCD) Then begin if((AgfsumehinchAggrfuncs)or(AgfavginchAggrfuncs)) and(Vartypenum <> vardate) Then //Modify Here ifVarisnulleh (Resultarr[agfsumeh]) ThenResultarr[agfsumeh]: =vElseResultarr[agfsumeh]: = Resultarr[agfsumeh] +v; ifAgfmininchAggrfuncs Then ifVarisnulleh (Resultarr[agfmin]) ThenResultarr[agfmin]:=vElse ifResultarr[agfmin] > V ThenResultarr[agfmin]:=v; ifAgfmaxinchAggrfuncs Then ifVarisnulleh (Resultarr[agfmax]) ThenResultarr[agfmax]:=vElse ifResultarr[agfmax] < V ThenResultarr[agfmax]:=v; End End; End; ifAgfavginchAggrfuncs Then //Modify Here if notVarisnulleh (Resultarr[agfsumeh]) ThenResultarr[agfavg]:= Resultarr[agfsumeh]/Resultarr[agfcounteh];End;
Fixed a bug where Dbgrideh used Tmemtableeh to average 0 in footers