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.
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
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/
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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?
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the assistance.
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;
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.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
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.
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