Change subreport based on Report.DeviceType
I would like to change the report output when the end user chooses save on the report preview in RAP code.
Example:
procedure ReportBeforePrint;
begin
if CompareText('TextFile',Report.DeviceType) = 0 then
begin
SubReport1.Visible := False;
SubReport2.Visible := True;
end
else
begin
SubReport1.Visible := True;
SubReport2.Visible := False;
end;
end;
Where SubReport1 is optimal for Printing/PDF and Subreport2 is optimal for CSV/Text.
However BeforePrint is only run once.
Can I Invalidate the report so it runs fully again when the user chooses save from preview window?
Example:
procedure ReportBeforePrint;
begin
if CompareText('TextFile',Report.DeviceType) = 0 then
begin
SubReport1.Visible := False;
SubReport2.Visible := True;
end
else
begin
SubReport1.Visible := True;
SubReport2.Visible := False;
end;
end;
Where SubReport1 is optimal for Printing/PDF and Subreport2 is optimal for CSV/Text.
However BeforePrint is only run once.
Can I Invalidate the report so it runs fully again when the user chooses save from preview window?
Comments
I tried adding a Group break on custom variable, and now It runs the above when re-printing to Textfile.
However Subreport2 gets stuck at the end of the first page writing to CSV file and preview just shows "Accessing Data".
If either Subreport is enabled individually they render ok, when changing the visibility as above it gets stuck.
I suggest using the OnFileDeviceCreate event to check the device being used and toggle the visibility of the subreport(s). In my quick test, this worked as expected. Below is my RAP code.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I still seem to have a problem, I run the report and Subreport1 renders ok in preview. When saving as .csv from preview form, The above RAP code switches the Subreport1 to Subreport2, but Subreport2 is getting stuck on "Accessing Data".
If I cancel the report, the CSV file contains some records not all.
It contains 15 lines, I would estimate that is what would be visible on a single page in the preview (although it is not rendering it in preview).
Each of the subreports contain no RAP code and printersetup is set to parent and parentwidth. the print behavior is pbChild.
Both subreports have the same pipeline assigned, the pipeline is linked to a datasource and datasource links to a TrxMemoryData. Only other pipleline parameter changed from default is the Username.
Any Ideas why it would get stuck on "Accessing Data"?
There are numerous reasons the report may be getting stuck. My suggestion would be to simplify your report as much as possible to try to isolate that reason. Start by removing all RAP code and the subreport that works correctly. Then begin simplifying the subreport until you get something working.
Finally begin gradually adding back to the report to find the cause of the problem.
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for the help.
I had already gone down that route, the only RAP code was OnFileDeviceCreate
Each of the subreports as singletons work individually ok.
if i reverse the logic for the OnFileDeviceCreate on the subreports then the other subreport gets stuck.
In the end it came down to a parent report with the 2 subreports, no rap code (except the OnFileDeviceCreate). A single pipeline assigned to both of the subreports.
For now I have arrived at an alternative solution to the problem, so all is well.
Thanks