merge two reports together

hsmhsm
edited 2:00AM in FastReport 4.0
I know the programmers' manual shows how to do this if you have saved reports ie
frxReport1.LoadFromFile('1.fr3');
frxReport1.PrepareReport;
frxReport1.LoadFromFile('2.fr3');
frxReport1.PrepareReport(False);
frxReport1.Print;
I do not have saved reports.
I have a form that generates sql and prepares an invoice report in one part of the application (optionally priniting it) and a different form that generates sql and prepares and prints a reminder letter.
I'd like to include a copy of the invoice report with the letter report.

In my my Invoice form I have a procedure TFrmInvoice.PrepareInvoice(invoiceID:integer) that correctly does all the work to make an invoice and ends with the line
FrmInvoice.frxRptInvoice.prepareReport(false);
The code in the reminder form does all the work to make the letter and ends with
FrmPrintInvoiceReminder.frxReportInvoiceReminderLetter.PrepareReport(true);
FrmInvoice.PrepareInvoice(TheInvoiceID); //<--- call the proc to prepare and append the invoice
FrmPrintInvoiceReminder.frxReportInvoiceReminderLetter.ShowPreparedReport; //<-- here I want to show them both
but I only get the letter shown, not the invoice.
How can I translate the code in the programmers manual to the situation when I am not calling LoadFromFile() ?
Howard

Comments

  • edited 2:00AM
    Hi Hsm, looks like this issue needs to be duplicated. Have you tried creating a support ticket on this yet?
  • edited March 2013
    hsm wrote: »
    How can I translate the code in the programmers manual to the situation when I am not calling LoadFromFile() ?

    Using memorystreams.

    save invoice to memorystream
    save letter to memorystream

    using a 3rd frxReport.component use

    frxReport1.LoadFromStream( invoiceStream );
    frxReport1.PrepareReport;
    frxReport1.LoadFromStream( letterStream );
    frxReport1.PrepareReport(False);
    frxReport1.Print;
  • hsmhsm
    edited March 2013
    technisoft wrote: »
    technisoft wrote: »
    How can I translate the code in the programmers manual to the situation when I am not calling LoadFromFile() ?

    Using memorystreams.

    save invoice to memorystream
    save letter to memorystream

    using a 3rd frxReport.component use

    frxReport1.LoadFromStream( invoiceStream );
    frxReport1.PrepareReport;
    frxReport1.LoadFromStream( letterStream );
    frxReport1.PrepareReport(False);
    frxReport1.Print;

    I did try that but I didn't use a third report. In algorithmic form I did the following
    Prepared letter report
    Stream to memory stream (s)
    Prepare invoice report
    Stream to the same memory stream (s)
    Set position of stream S back to 0
    Load Letter report from stream(s)
    Print letter report

    Unfortunately though, although I had streamed both reports to the same stream, and loaded the whole stream back in, only the first report (letter) report was printed

    I'll have another go using a third, empty report as you sugest.
  • hsmhsm
    edited 2:00AM
    technisoft wrote: »
    Using memorystreams.

    Thank you technisoft, I eventually got it working that way. I am using quite a few script variables in the letter report and found that I had to repeat setting up the script variables again in the combined report. So the solution was not quite as slick as I thought it would be compared with simply printing one report after another.
    However in case anyone else is following this below is the code I finally used.
    (The procedure names should be self explanatory )
    try
        GenerateDataSetForLetter(TheInvoiceID); //run sql and return the data
    
        LetterStream:= TmemoryStream.Create;
        InvoiceStream:= TmemoryStream.Create;
    
        SetLetterReportVariables; //set script variables from the data generated
        frxReportInvoiceReminderLetter.PrepareReport(true) ; //make letter report
        frxReportInvoiceReminderLetter.SaveToStream(LetterStream);
    
       //repeat above two lines on a different form to make and save invoice report to a different stream
        FrmInvoice.PrepareAndSaveInvoiceToStream(TheInvoiceID,InvoiceStream);  
    
        LetterStream.Position := 0;   //reset streams to the beginning
        InvoiceStream.Position :=0;
    
        SetCombinedReportVariables;   //set the script variables again in the combined report
    
        frxReportLetterAndInvoiceCombined.LoadFromStream(LetterStream); //load and prepare letter
        frxReportLetterAndInvoiceCombined.PrepareReport(true);
    
        frxReportLetterAndInvoiceCombined.LoadFromStream(InvoiceStream);//append the invoice
        frxReportLetterAndInvoiceCombined.PrepareReport(false);
    
        frxReportLetterAndInvoiceCombined.print; //print both pages together
    
     finally
       LetterStream.free;
       InvoiceStream.Free;
      end;
    
  • edited March 2013
    Sorry, wanted to say something but first have to find the right words. >

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.