Sum in Group Header

edited April 2008 in FastReport 4.0
I want to design a report which like below layout:

<Group Header1> - Sum(<QTY>,Masterdata1) & Sum(<AMOUNT>,Masterdata1)
<Group Header2> - Sum(<QTY>,Masterdata1) & Sum(<AMOUNT>,Masterdata1)
<Group Header3> - Sum(<QTY>,Masterdata1) & Sum(<AMOUNT>,Masterdata1)

In my draft report I can successfully sum up the value in Red summary, but when I add another Sum(QTY) in Group Header 2 the following error happen:

Format '%2.2n' invalid or incompatible with argument

Below is my code: (I have remarked two line, if remove it the above error will happen)
var
List1,List2,List3,List4,List5: TStringList;
i,j,k: Integer;

procedure frxReport1OnStartReport(Sender: TfrxComponent);
begin
List1:=TStringList.Create;
List2:=TStringList.Create;
List3:=TStringList.Create;
List4:=TStringList.Create;
List5:=TStringList.Create;

end;

procedure Page1OnBeforePrint(Sender: TfrxComponent);
begin
i:=0;
j:=0;
k:=0;
end;

procedure GroupHeader1OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass then
begin
Memo2.Text:= List1;
Memo10.Text:= List2;

end;
end;

procedure GroupHeader2OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass then
begin
IF <TEST>=0 THEN GroupHeader2.visible:=False;
Memo4.Text:= List3[j];
//Memo3.Text:= List4[j];
end;
end;

procedure GroupHeader3OnBeforePrint(Sender: TfrxComponent);
begin
if Engine.FinalPass then
begin
IF <TEST1>=0 THEN GroupHeader3.visible:=False;
Memo7.Text:=List5[k];
end;
end;

procedure GroupFooter1OnBeforePrint(Sender: TfrxComponent);
begin
if not Engine.FinalPass then
begin
List1.Add(Format('%2.2n',[SUM(<Query1."QTY">,MasterData1)]));
List2.Add(Format('%2.2n',[SUM(<AMOUNT>,MasterData1)]));

end;
Inc(i);
end;

procedure GroupFooter2OnBeforePrint(Sender: TfrxComponent);
begin
if not Engine.FinalPass then
begin
List3.Add(Format('%2.2n',[SUM(<AMOUNT>,MasterData1)]));
//List4.Add(Format('%2.2n',[SUM(<Query1."QTY">,MasterData1)]));
end;
Inc(j);
end;

procedure GroupFooter3OnBeforePrint(Sender: TfrxComponent);
begin
if not Engine.FinalPass then
begin
List5.Add(Format('%2.2n',[SUM(<AMOUNT>,MasterData1)]));
end;
Inc(k);
end;

procedure frxReport1OnStopReport(Sender: TfrxComponent);
begin
List1.Free;
List2.Free;
List3.Free;
List4.Free;
List5.Free;
end;


Anyone know how to solve this problem?

Thanks and Best regards

pcleslie

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 5:46AM
    read what the error says
    Format '%2.2n' invalid or incompatible with argument.
    qty is probably an integer value an therefore the format is incorrect.
    you probably could have used vartostr(expression).
    also make sure you do not have a null value.
    you do not need to free the tstring list they will be destroyed when the report closes.
    you can create them in the empty begin end. block of the code page
    my own prefrence is to use tfrxarrays
    to gather values, they can be created the same way as tstringlists, and only do formating when i move the value
    into the memos text.
    in obp of header
    make sure to set index value
    if not finalpass initialize the array[index]value to 0.
    if final pass move array[index]value into memo's text applying formatting where needed.
    also better to name arrays or stringlists with more understandable names makes code easier to read when trouble shooting, and when posting it is wise to state what version you are working with.

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.