New Blog Post: PDF/A and Metadata

Changing text on a header band label when printing sub-report

edited December 2016 in Subreports
I'm attempting to do something which seems simple in theory, but is
turning out to be very difficult in practice.

I have a report that prints a bunch of sub-reports in its summary band.
When one of these sub-reports is printing, I need a label in the
reports header band to have additional text appended to it.

I initially thought I could use the
TppChildReport.OnStartFirstPass/OnEndFirstPass events to set a flag,
which could be used to determine whether this extra text should be
appended. But due to the way the events fire, this isn't a reliable
approach. In particular it breaks down when navigating pages in the
report preview, or when printing a sub-range or pages, as the
OnStartFirstPass event may not fire when expected.

I then thought I could duplicate the parent report's header in the
sub-report, and change the label text on the sub-report header only.
But in order for the sub-report header to be shown, I had to set the
TppSubReport.PrintBehaviour property to pbSection. And when I do that,
the sub-report is not printing where I need it to, as I can't use the
ShiftRelativeTo property any more.

Any hints of how to achieve this seemingly simple task would be
greatfully received.

--
Cheers,
David Clegg
https://www.twitter.com/delphijunkie

"Facts are meaningless. You could use facts to prove anything that's
even remotely true." - Homer Simpson

Comments

  • edited December 2016
    Hi David,

    Which version of ReportBuilder and Delphi are you using?

    You may have to experiment with different report events to get the
    effect you are after and simply check the boolean properties
    Report.FirstPass or Report.SecondPass to be sure the correct code is
    executing.

    Of course the best way to achieve this would be pre-process your data
    and compile the header label before printing the report.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited December 2016
    Nico Cizik (Digital Metaphors) wrote:


    Delphi XE7, and ReportBuilder 12.03


    I've tried all the likely looking events, and
    OnStartFirsPass/OnEndFirstPass seem like the ones to use. The issue is
    how they fire.

    For example, if my master report has 5 pages worth of data in its
    detail band's dataset, the OnStartFirstPass event will fire whenever
    page 5 is rendered (either when printing the report or in the report
    preview window). The OnEndFirstPass event will fire after the last page
    of the subreport is rendered.

    Now consider that my subreport has 1 page worth of data to display ,
    and that its title band is configured to force a page break (giving 6
    report pages in total). If we are in the report preview, this is what
    happens in various navigation scenarios.

    Page 4 -> Page 5
    Page 5 renders
    TppChildReport.OnStartFirstPass fires
    Page 5 -> Page 6
    Page 6 renders
    TppChildReport.OnEndFirstPass fires
    Page 6 -> Page 5
    Page 5 renders
    TppChildReport.OnStartFirstPass fires
    Page 5 -> Page 4
    Page 4 renders
    Page 4 -> Last page
    Page 6 renders

    As you can see from the above, I can't reliably use the
    OnStartFirstPass & OnEndFirstPass events of the subreport to determine
    if we're rendering one of its pages. Whenver the page that contains the
    subreport is rendered, the OnStartFirstPass event fires, even if we're
    navigating backwards. But when we go to the previous page, the
    OnEndFirstPass event doesn't fire.

    I can work around that if I also keep track of the page number being
    rendered, but this breaks down if we navigate directly to the last
    page, as OnStartFirstPass never fires. It also breaks down if the user
    prints a page range that only includes the subreport (in this case,
    printing only page 6).


    I've also tried to utilise these properties, but with no success yet.


    I wouldn't mind hearing more about this, but I suspect your approach
    may still break down.

    What we have is a label that needs to show some data if the master
    report (or other subreports) is rendering its elements, but show other
    data if a certain subreport is rendering its elements. It's the
    determination of when this subreport is rendering its elements that is
    proving problematic.

    --
    Cheers,
    David Clegg
    https://www.twitter.com/delphijunkie

    "If there's one thing I've learned, it's that life is one crushing
    defeat after another until you just wish Flanders was dead." - Homer
    Simpson
  • edited December 2016
    Nico Cizik (Digital Metaphors) wrote:


    OK, so I've got a solution that seems to be working, based on checking
    these properties. In the first pass, I'm saving the first page number
    of the sub-report. This is done in the OnPrint event of one of the
    labels on the sub-report.

    Then on the second pass of the report, I can refer to this and
    determine if we are on a page in the sub-reports page range.

    Thanks for pushing me in the right direction.

    --
    Cheers,
    David Clegg
    https://www.twitter.com/delphijunkie

    "Facts are meaningless. You could use facts to prove anything that's
    even remotely true." - Homer Simpson
  • edited December 2016
    Hi David,

    Great! Glad you were able to find a solution.

    Moving forward we hope you will consider upgrading to the latest version
    of ReportBuilder. We have added hundreds of new features, enhancements,
    and bug fixes since RB 12 and rely on customers like you to keep the
    product moving forward, and provide high quality support.

    See the following link for what has been added for RB 18. Use the side
    bar to see the new features for previous versions as well.

    http://www.digital-metaphors.com/rbWiki/General/What's_New/RB_18

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.