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?

Comments

  • edited October 7
    Update:

    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.
  • Hi Steven,

    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.



    procedure ReportOnFileDeviceCreate;
    begin
    if Report.FileDevice is TppPDFDevice then
    begin
    Subreport1.Visible := False;
    Subreport2.Visible := True;
    end
    else if Report.FileDevice is TppTextFileDevice then
    begin
    Subreport1.Visible := True;
    Subreport2.Visible := False;
    end;
    end;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Thank you.

    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"?
  • Hi Steven,

    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.


    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Nico,

    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
Sign In or Register to comment.