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:
Procedure Tcustommemtableeh.getaggregatedvaluesforrange (FROMBM, Tobm:tunibookmarkeh; fieldname:string; var Resultarr:taggrresultarr; Aggrfuncs:taggrfunctionseh); var fromrn, Torn:integer; I:integer; V:variant; Vartypenum:integer; Fieldindex:integer;begin Resultarr[agfsumeh]: = Null; Resultarr[agfcounteh]: = 0; RESULTARR[AGFAVG]: = Null; Resultarr[agfmin]: = Null; Resultarr[agfmax]: = Null; If not Active then Exit; If FROMBM <> Nilbookmarkeh then if Unibookmarkvalid (FROMBM) then FROMRN: = Unibookmarktorecno (FROMBM) E LSE Exit ELSE FROMRN: = 1; If TOBM <> Nilbookmarkeh then if Unibookmarkvalid (TOBM) then torn: = Unibookmarktorecno (TOBM) Else Exit else torn: = RecordCount; if (FieldName = ") and (Aggrfuncs = [Agfcounteh]) THEN begin for I: = FromRN-1 to ToRN-1 do Resultarr[agfcounteh ]: = Resultarr[agfcounteh] + 1; Exit; End If FRecordsView.MemTableData.DataStruct.FindField (FieldName) = nil then Exit; Vartypenum: = FRecordsView.MemTableData.DataStruct.FieldByName (FieldName). Getvardatatype; Fieldindex: = FRecordsView.MemTableData.DataStruct.FieldIndex (FieldName); For I: = FromRN-1 to ToRN-1 do begin V: = Frecordsview.recordview[i]. Rec.value[fieldindex, Dvvvalueeh]; If not Varisnulleh (v) THEN BEGIN if (Agfcounteh in Aggrfuncs) or (Agfavg in Aggrfuncs) then Resultarr[agfco Unteh]: = Resultarr[agfcounteh] + 1;<span style= "White-space:pre" ></span>//when the setting is averaged, only one count cumulative if (VarT Ypenum in [Varsmallint, Varinteger, Varsingle, vardouble, varcurrency,{$IFDEF eh_lib_6} varshortint, VarWord, VarI Nt64, varlongword,{$ENDIF} varbyte, Vardate]) or (Vartypenum = VARFMTBCD) THEN BEGIN if (Agfsumeh in A Ggrfuncs) and (Vartypenum <> vardate) Then if Varisnulleh (Resultarr[agfsumeh]) then Resultarr[ag Fsumeh]: = v else Resultarr[agfsumeh]: = Resultarr[agfsumeh] + V; If agfmin in Aggrfuncs then If Varisnulleh (Resultarr[agfmin]) then resultarr[agfmin]: = v else if resultarr[agfmin] > V Then resultarr[agfmin]: = v; If Agfmax in Aggrfuncs then if Varisnulleh (Resultarr[agfmax]) then Resultarr[agfmax]: = v Els e if Resultarr[agfmax] < V then Resultarr[agfmax]: = v; End END; End If <span style= "color: #ff0000;" >agfMax</span> in Aggrfuncs then<span style= "White-space:pre" ></span>//averaging, the trigger condition here is Agfmax .... If not Varisnulleh (Resultarr[agfsumeh]) then Resultarr[agfavg]: = <span style= "color: #ff0000;" >ResultArr[agfSumEh]</span>/Resultarr[agfcounteh]; This value should be 0;end here because the sum of Agfsumeh is not summed at agfavg time;
Modification Method:
1. Open Memtableeh.pas
2. Find the Getaggregatedvaluesforrange function and modify it as follows:
Procedure Tcustommemtableeh.getaggregatedvaluesforrange (FROMBM, tobm:tunibookmarkeh; fieldname:string; var Resultarr:taggrresultarr; Aggrfuncs:taggrfunctionseh);var fromrn, torn:integer; i:integer; v:variant; VarTypeNum: integer; fieldindex:integer;begin Resultarr[agfsumeh]: = null; Resultarr[agfcounteh]: = 0; RESULTARR[AGFAVG]: = null; Resultarr[agfmin]: = null; Resultarr[agfmax]: = null; if not Active then Exit ; if FROMBM <> nilbookmarkeh then if Unibookmarkvalid (FROMBM) then FROMRN: = Unibookmarktorecno (FROMBM) Else exit else FROMRN: = 1; if TOBM <> Nilbo Okmarkeh then If Unibookmarkvalid (TOBM) then torn: = Unibookmarktorecno (TOBM) &nbs P Else exit else TORN: = recordcount; if (FieldName = ") and (Aggrfuncs = [Agfcounteh]) the n begin  for I: = FromRN-1 to ToRN-1 do Resultarr[agfcounteh]: = Resultarr[agfcounteh] + 1; Exit; end; if FRecordsView.MemTableData.DataStruct.FindField (FieldName) = nil then Exit; Vartypenum: = FRecordsView.MemTableData.DataStruct.FieldByName (FieldName). getvardatatype; Fieldindex: = FRecordsView.MemTableData.DataStruct.FieldIndex (FieldName); for I: = FromRN-1 to ToRN-1 do begin V: = frecordsview.recordview[i]. Rec.value[fieldindex, dvvvalueeh]; if not Varisnulleh (v) then begin if (AGFC Ounteh in Aggrfuncs) or (Agfavg in Aggrfuncs) then Resultarr[agfcounteh]: = Resultarr[agfcounte H] + 1; if (vartypenum in [Varsmallint, Varinteger, Varsingle, vardouble, varcurrency,{$IFDEF eh_lib_6 } varshortint, Varword, VarInt64, varlongword,{$ENDIF} varbyte, Vardate]) or (Vartypenum = VARFMTBCD) then begin if <spa n style= "color: #009900;" > ((Agfsumeh in Aggrfuncs) or (Agfavg in Aggrfuncs)) </span> and (Vartypenum <> vardate) then <span style = "COLOR: #3333ff;" >//here to edit </span> if Varisnulleh (Resultarr[agfsumeh]) then Resultarr[agfsumeh]: = v else Resultarr[agfsumeh]: = Re Sultarr[agfsumeh] + v; If agfmin in Aggrfuncs then<span style= "White-space:pre" ></spa n> if Varisnulleh (Resultarr[agfmin]) then Resultarr [Agfmin]: = v else if resultarr[agfmin] > v then &N Bsp Resultarr[agfmin]: = v; If Agfmax in Aggrfuncs then &NBSp If Varisnulleh (Resultarr[agfmax]) then Resultarr[agfmax]: = v ELSE if Resultarr[agfmax] < v then Resultarr[agfmax]: = v;  ; end end; end; if <span style= "color: #009900;" >agfavg </span>in Aggrfuncs then <span style= "color: #3333ff;" >//here Modify </span> if not Varisnulleh (Resultarr[agfsumeh]) then RESULTARR[AGFAVG ]: = Resultarr[agfsumeh]/resultarr[agfcounteh];end;
Fixed a bug where Dbgrideh used Tmemtableeh to average 0 in footers