Fixed a bug where Dbgrideh used Tmemtableeh to average 0 in footers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.