generating sum using wpreporter

  • I am using wpreporter to generate sum value of one column, it works well when using one group in the report. but now i want to use wpreporter to generate report of master-detail structure. it can sum value of master records, but it can't sum value of detail values of one master record. here is an example, the expecting result is following:

    Code
    master    1    1001detail      1    2              1    3              1    4sum              9                   master    2    1002detail      2    1              2    3              2    4 sum            8grand sum    2003

    but now i get the result is:



    the problem is the sum of detail values are sum of all the detail records,but i want is the sum of detail records of same master record.

    did i describe my question clearly?

    please help me

    Einmal editiert, zuletzt von littlegg (12. Juli 2006 um 04:36)

  • i use following code to sum totals

    Code
    if Sender<>SourceText.Memo then   try      tbl := pobj.ParentPar.ParentTable;      colnr := pobj.ParentPar.ColNr;      sum := 0;      if pobj.SOURCE='TOTALNR' then // Sum in this Column ------------------------      begin        list := TList.Create;        try          tbl.GetObjList([wpobjMergeField],list,nil,'NR');          for i:=0 to list.Count-1 do          //OPTION: if TWPTextObj(list[i]).ParentPar.ColNr=colnr then  //<--- only in same COLUMN!!!          begin            // sum := sum + StrToFloat(TWPTextObj(list[i]).EmbeddedText);            sum := sum + TWPTextObj(list[i]).EmbeddedTextAsFloat;          end;        finally         list.Free;        end;      end else // Sum on this page with same parent table ----------------------      begin        for i:=0 to page.EmbeddedObjectCount([wpobjMergeField],pobj.Source)-1 do        if page.EmbeddedObjectGet(i).ParentPar.ParentTable=tbl then // Only sum up in same table!        begin         // sum := sum + StrToFloat(page.EmbeddedObjectGet(i).EmbeddedText);         sum := sum + page.EmbeddedObjectGet(i).EmbeddedTextAsFloat;        end;      end;      ResultText := FloatToStr(sum);      UseIt := TRUE;   except      ResultText := 'ERR';      UseIt := TRUE;      if PaintCanvas<>nil then         PaintCanvas.Font.Color := clRed;   end;

    but this line

    Code
    tbl.GetObjList([wpobjMergeField],list,nil,'NR');

    sum all the column in whole table, it is not wanted,i want to sum only in one master record.

    how should i do?

    • Offizieller Beitrag

    Hi,

    the TWPTextObj reported by GetObjList all have a property ParentPar . This reference can be used to check the location of the object in the document - for example serach for hidden text which marks the different queries.

    You could in column 1 insert the master record id - as hidden text. Using
    ParentPar.ParentRow.FirstCol you can check for the id
    https://www.wpcubed.com/manuals/wptool…_TWPTextObj.htm
    Julian