Create Memo and calculate the SUM with code (script)

edited August 2016 in FastReport VCL 5
I have this script code to create my report in the runtime
                                  
procedure Page1OnBeforePrint(Sender: TfrxComponent);
var
i, L1, L2: integer;
L: extended;
S: string;
begin
 L1 :=0;
 while not FDQuery1.eof do
 begin
 inc(L1);
 FDQuery1.next;
 end;
  L2 :=0;
 while not FDQuery2.eof do
 begin
 inc(L2);
 FDQuery2.next;
 end;

 L := 1200/(L1+L2);

 i :=0;
 FDQuery1.first;
 while not FDQuery1.eof do
 begin
 inc(i);
 S := FDQuery1.FieldByName('FieldValue').AsString;
 BuiltMemo('nMemo'+ inttostr(i),<FDQuery1."FieldName">,12, 30, L, GroupHeader1, False);
 BuiltMemo('vMemo'+ inttostr(i),'[<MemTable."'+S+'">]',0, 28, L, MasterData1, True);
 BuiltMemo('sMemo'+ inttostr(i),'[SUM(<MemTable."'+S+'">,MasterData1)]',4, 18, L, PageFooter1, True);
 BuiltMemo('tMemo'+ inttostr(i),'[SUM(<MemTable."'+S+'">,MasterData1)]',4, 18, L, ReportSummary1, True);
 FDQuery1.next;
 
 FDQuery2.first;
 while not FDQuery2.eof do
 begin
 inc(i);
 S := FDQuery2.FieldByName('FieldValue').AsString;
 BuiltMemo('nMemo'+ inttostr(i),<FDQuery2."FieldName">,12, 30, L, GroupHeader1, False);
 BuiltMemo('vMemo'+ inttostr(i), '[<MemTable."'+S+'">]',0, 28, L, MasterData1, True);
 BuiltMemo('sMemo'+ inttostr(i),'[SUM(<MemTable."'+S+'">,MasterData1)]',4, 18, L, PageFooter1, True);
 BuiltMemo('tMemo'+ inttostr(i),'[SUM(<MemTable."'+S+'">,MasterData1)]',4, 18, L, ReportSummary1, True);
 FDQuery2.next;
 end;
end;
 
procedure BuiltMemo(Name, Text: string; Top, Height, Width: Extended; Parent: TfrxBand; IsCurrency: boolean);
 var
 Memo: TfrxMemoView;
begin
 Memo := TfrxMemoView.create(parent);
 Memo.name := name;
 Memo.Text := Text;
 Memo.top := top;
 Memo.Height := height;
 Memo.Width := width;
 memo.halign := hacenter;
 memo.valign := vacenter;
 Memo.Align := baRight;
 Memo.HideZeros := True;
 if IsCurrency then
 begin
 Memo.DisplayFormat.FormatStr := '%2.2m';
 Memo.DisplayFormat.Kind := fkNumeric;
 end;
end;

After showing the report All work fine but in the PageFooter1 and ReportSummary1 all Memo are Empty (no Totals)
Note: I am using a Memory Table (TFDMemoTable) in TdataModule form.

Please, Help me to solve this problem.
All suggestions are welcome.

Comments

  • edited 2:53PM
    Solved.

    By putting the code between
    begin

    end.

    Not in the function (page1OnBeforePrint).

    Thanks for all
  • bestwail wrote: »
    Solved.

    By putting the code between
    begin

    end.

    Not in the function (page1OnBeforePrint).

    Thanks for all
    Your information is also useful for us.

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.