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:
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
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.
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.