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

NoData behavior

Is there any way to detect that the report has no any pages before actually printing?
In other words I need to know if report has data even before preview window appear.
I don't want to allow user print or save blank pages ([ndBlankPage]).
For now I did this like:
 
function ReportHasRecords(AReport: TppReport): boolean;
  begin
    AReport.Publisher.CachePages := True;
    AReport.Publisher.Publish;
    Result := (AReport.PageCount > 0);
    AReport.Reset;
  end;
...
 if ReportHasRecords(AReport) then
        AReport.Print
else
ShowMessage('There is no Data in the Report');
But it decrease report execute speed and cause many issues during actually Report print.
Could You help me?

Comments

  • Hi Ruvim,

    The Preview toolbar buttons should be disabled when there are no pages for [ndBlankPage].

    In testing I found the Export button is not being disabled and the Viewer PopupMenu is still visible. I created a patch for RB 22.03 to resolve the issues. You can email support@ and request the patch.

    The Report.AfterOpenDataPipelines event can be used to check for no data. (But with the above in place I don't think it is needed)

    if myReport.DataPipeline.Bof and myReport1.DataPipeline.Eof then
    // report has no data


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • I did this before. But the problem is that AfterOpenDataPipelines fire only after we call Report.Print.
    So if we want to Print this via PDF printer (for example), we will see Printer Dialog, we will be able to set output file name and only after this we will got AfterOpenDataPipelines Event.
    In my example above a find the way to do this without actually Report.Print (using AReport.Publisher.Publish). But I have some troubles with complex Reports using this method.
    Is there any way to OpenDataPipelines or calculate Report pages without Report.Print?
    See my example video for more details:
    https://dropmefiles.com/GXJR9
  • Hi Ruvim,

    I performed some tests:

    - print to preview, toolbar buttons are disabled
    - print to printer, no print job is sent to printer
    - export to file, no file created

    - print to MS Print to PDF driver, empty file
    - Print to MS XPS document driver, empty file

    The last two are a bug/limitation of the MS drivers.

    To work around, you can set Report.CachePages True, create a temp device, print to devices, then check the number of pages.

    Example:


    uses
    ppDevice;

    var
    lTempDevice: TppDevice;
    begin

    ppReport1.Publisher.Clear;
    ppReport1.CachePages := True;

    lTempDevice := TppDevice.Create(nil);

    try

    lTempDevice.Publisher := ppReport1.Publisher;

    // generate report to page cache
    if ppReport1.InitializeParameters then
    ppReport1.PrintToDevices;

    finally
    lTempDevice.Free;

    end;

    if ppReport1.Publisher.PageCount = 0 then
    ShowMessage('No Pages')
    else
    ppReport1.Print;

    end;



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
Sign In or Register to comment.