Printing multiple sums in GroupHeader

ngkngk
edited 2:09PM in FastReport 4.0
Hello,

according to the manual it is possible to print a sum in a group header by using double pass like this:
procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass then
   Memo8.Text := 'Sum: ' + Get(<Group."CustNo">);
end;
 
procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
begin
 Set(<Group."CustNo">,
   FloatToStr(SUM(<Group."ItemsTotal">,MasterData1)));
end;
 
begin
 
end.

And this actually works. But how can I calculate multiple sums in the GroupHeader? Obviously, I cannot use the same variable as it would overwrite the other value. So I tried adding a new variable. It looks like this now:
procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass then
   Memo8.Text := 'Sum: ' + Get(<Group."CustNo">);
   Memo9.Text := 'Sum: ' + Get(<test>);
end;
 
procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
begin
 Set(<Group."CustNo">,
   FloatToStr(SUM(<Group."ItemsTotal">,MasterData1)));
 Set(<test>,
   FloatToStr(SUM(<Group."SomeOtherValue">,MasterData1)));
end;
 
begin
 
end.

But this does not work as expected. It always prints the sum of the previous group. Why is that? How can I use multiple sums in a group header correctly?

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 2:09PM
    create single dimension arrays for each each of the other sum values.
    at script start
    var ar: TfrxArray;
    in the empty begin endblock of sctript
    ar := TfrxArray.Create;
    in the appropriate band set the valueof the array
    ar[(<Group."CustNo">] := FloatToStr(SUM(<Group."SomeOtherValue">,MasterData1));
  • gpigpi
    edited 2:09PM
    Don't try to read manual, try to understand it
    procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
    begin
    if Engine.FinalPass then
    Memo8.Text := 'Sum: ' + Get('Sum1' + <Group."CustNo">);
    Memo9.Text := 'Sum: ' + Get('Sum2' + <Group."CustNo">);
    end;
    
    procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
    begin
    Set('Sum1' + <Group."CustNo">,
    FloatToStr(SUM(<Group."ItemsTotal">,MasterData1)));
    Set('Sum2' + <Group."CustNo">,
    FloatToStr(SUM(<Group."SomeOtherValue">,MasterData1)));
    end;
    
  • ngkngk
    edited February 2015
    Thank you very much. This works. But why does it work? Does FastReport look for the GroupCondition in the variable name?
    But anyway, at least it works now. Thank you.

    I have got one more similar question. Is it also possible to print sums in Header?

    edit: sorry. you don't need to answer that. of course it works the same way.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.