Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Multiple Reports vs. Subreport

Delphi 12.1, RB 22.06
I have created a Production Overview Report that has 12 sub-reports within a single report. The problem is that I randomly get the error "Invalid Operation in GDI + [Code2]". I assume it is memory issue from so many sub-reports. So I am considering breaking it into several separate reports but merging them together for viewing. In researching my Report Builder options, I considered 2:
1. Merge reports for viewing in a single preview screen. It appears this is not possible based on what I have read. Is it correct that this is not an option? If it is, can you point me to a demo project?
2. Merge reports into a single pdf file and view using normal pdf viewer. I find in your support DB where this is an option but the post are pretty old. Can you point me a to a demo project where this is done?

I appreciate any suggestions you might have.

Thank you.

Comments

  • Hi Bob,

    1. You may have a memory leak (or there may be one in RB) that needs to be addressed which is causing this error. I suggest turning on memory leak detection and re-testing before moving forward.

    2. There are numerous ways to merge reports. There is a blog series and articles about them (I'm still working on the final post) :). See below...

    Merging with Subreports:
    https://www.digital-metaphors.com/merging-reports-part-1-merging-with-subreports/

    Merging with Archives
    https://www.digital-metaphors.com/merging-reports-part-2-merging-archives/

    Merging Files
    https://rbwiki.digital-metaphors.com/output/pdf/how-to-merge-multiple-reports-into-one-pdf/
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • I will do some checking for memory leaks. I built the report one sub-report at a time, testing along the way. Once I reached around 10 sub-reports is when the error started occuring. Each sub-report uses a different query but each query (sql server) has less than 10 records as they are aggregate queries. The report is fast but returns the error stated. Because of the number of queries and sub-reports, I will look at the links you provided and investigate handling as separate reports merged together to be viewed as a single pdf file.

    Do you think this would be a better solution than having so many sub-reports in one report?
    Also, am I correct in understanding the RB viewer will not allow me to view the pdf file and I will need to use some other pdf viewer?
  • Hi Bob,

    After some research, it appears the error you are getting usually stems from image handling scenarios. Do your subreports contain a large number of images? Are you manually processing images in code? Are there large images?

    As a first test, try toggling the visibility of any images in your report and see if that is the cause of the error.

    >>Do you think this would be a better solution than having so many sub-reports in one report?

    We have customers using 30+ subreports successfully so the amount of subreports is likely not the issue. It's probably the content.

    >>Also, am I correct in understanding the RB viewer will not allow me to view the pdf file and I will need to use some other pdf viewer?

    Mostly correct. Although it may be possible to use our PDF component to display an exported PDF in the previewer. This would require exporting the original report(s) to PDF, then loading that PDF in a different report (with a PDF Component) and previewing.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • The report I initially designed had 15 subreports with no images and I was getting the GDI error. However, I have moved on to the concept splitting up the subreports into 3 separate reports (with 5 sureports each) and generating pdf files. I am using your suggestion of merging the PDFs together into a single file and it is working perfectly. This works for me in this case as it is a unique report that is only generated by a couple users on a monthly basis.

    Thanks for the assistance.
  • Well I spoke too soon. I have three reports and each has 5 subreports. I appears to run correctly but does not. It outputs all three reports to a single pdf file. The report headers are correct. However the subreports are not. The first report is correct but the 2nd and 3rd have the correct headings but they have the subreports of the first report. It is the strangest thing.

    Below is my code that I am using. It seems opening of reports 2 and 3 are keeping the original subreports. Please let me know what suggestions you might have. Thanks.

    procedure TfrmProduction.RunProductionReports2;
    var
    lPDFDevice: TppPDFDevice;
    begin
    ppReport1.Template.DatabaseSettings.Name :='Production - Containers';
    ppReport1.Template.LoadFromDatabase;

    ppReport2.Template.DatabaseSettings.Name :='Production - Restrooms';
    ppReport2.Template.LoadFromDatabase;

    ppReport3.Template.DatabaseSettings.Name :='Production - Revenue';
    ppReport3.Template.LoadFromDatabase;

    lPDFDevice := TppPDFDevice.Create(nil);
    lPDFDevice.PDFSettings.OpenPDFFile :=True;
    lPDFDevice.FileName :='C:\Temp\EasyHaul\Production-Combined.pdf';

    lPDFDevice.EndPrintJob := False;

    lPDFDevice.Publisher :=ppReport1.Publisher;
    ppReport1.PrintToDevices;

    lPDFDevice.Reset;
    lPDFDevice.Publisher := ppReport2.Publisher;
    lPDFDevice.StartPrintJob := False;
    ppReport2.PrintToDevices;

    lPDFDevice.Reset;
    lPDFDevice.Publisher := ppReport3.Publisher;
    lPDFDevice.StartPrintJob := False;
    lPDFDevice.EndPrintJob := True;
    ppReport3.PrintToDevices;

    lPDFDevice.Free;
    end;
  • Hi Bob,

    My guess is that this is a template issue. If you load your templates and print individually, do you still get the same behavior?

    Also, since you are loading templates, there is no need to have three report components. You could simply load each template into the same report.
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • If I run the 3 reports individually without attempting to merge them, they come out correctly. But if I run them merging as shown before, the headers are correct but the last two reports use the subreports from report 1 but the data from there correct report. It is quite strange.

    I will try using a single report and loading them separately to see if that makes a difference. I used 3 separate reports because I was afraid that loading from template on reports 2 and 3 would mess up the printing to device with EndPrintJob being false. But I will try and let you know.

    Thanks.
  • Nico,
    I appreciate all of the help. I tried the last suggestions but got the same results. In the interest of time, I have chosen to run each report separately to separate pdf files and use a different component to merge the pdf files and then display them. Everything else I tried rendered the subreports from the first report. I hate leaving something unresolved but at this point I must. Again thank you for all of your help.
    Bob
  • PS: If something comes to your mind that might be causing the issue, let me know and I will give it a test.
Sign In or Register to comment.