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

Creating multiple TppPageStyle objects at runtime

edited March 2011 in Component Writing
Hi all.

I would like you to know how I can create multiple pagestyle objects at
runtime.

I want to use two pagestyle bands in my report:
one with PageSetting = psAll and one with PageSetting = psFirstPage;

When I create two pagestyles (with properties set differently) by
editing the RTM file manually. this seems to work and when I open this
RTM file in the ReportBuilder designer, I see two pagestyle bands.

But when I use
I get only one PageStyle band in my report.

Thanks for your help.

David Bakker

Comments

  • edited March 2011
    Hi David,

    ReportBuilder was not designed to allow two pagestyle bands in a single
    report. My suggestion would be to place two subreports inside a single
    pagestyle band and toggle the visibility of each based on the page being
    displayed/printed.


    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2011
    Hi Nico,

    thanks for your answer.

    Your idea is a possibility, but it requires raCode to be generated
    during runtime, as the subreports need an OnPrint event then.

    How can I create an OnPrint event for a component through Delphi?
    In the RTM files I only find the raCodeModule in its encoded form.

    Regards,
    David Bakker
  • edited March 2011
    Hi David,

    I'm a bit unclear about your question. It is possible to implement all
    the events available in RAP with Delphi. At no point is RAP code
    required to accomplish something with ReportBuilder.

    If you need to implement a report event in Delphi, simply select the
    component, then inside the Delphi Object Inspector (event tab) select
    the event you would like to implement.


    Regards,

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

    Best Regards,

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

    what David is trying to build is the following:
    we store all our reports in external .rtm files and load them at runtime
    to print/view our reports.
    David has created a module to allow our customers to create "background
    styles" (our name for the feature) to procude the normal reports on.
    Internally each "background style" is an .rtm file with only one Page
    Style band that the user can put footer information of a company logo on.
    For each of our reports the user can then select a selection (even more
    than 1 "background style" from the list. It also allows to configure
    that certin background styles should only be printed in case of export
    to PDF (for example the logo) but now during printing (as the logo would
    already be on the paper they use).
    After loading the normal report from the .rtm file we open one
    "background style" rtm after the other and move the components from the
    page style to the dynamically created page style band of the report.
    It works fine so far, even with several "background style" .rtm files.

    We are now at the point that we would want to do a bit more and for
    example create a "backgroudn style" ppLabel with the senders address to
    be printed in the window area of an envelope. They requires that this
    ppLabel would only be printed on the first page of the report.
    If we put it on the page style together with all the other components
    like logo or footer lines, we can either set the page style to be
    printed only on the first page (correct for our address line, but will
    miss the logo on 2nd page) or on any page (correct for the logo, but
    wrong for the address line).
    The question is: can we DYNAMICALLY create code like an OnBeforePrint
    event that will set the visible property of one component to false once
    the pageNo > 1?
    Or do you see any other option to solve this problem?

    Environment: Delphi XE, RB 12.04 Enterprise

    Thanks for your help,

    Stphan
  • edited March 2011
    Hi,

    by testing with the subreports, I have found another possibility to
    reach the desired effect.

    I created a report containing a pagestyle. In this pagestyle I put all
    components, which shall appear on every page. Therefore I set the
    pagestyle property to PageSetting = psAll.

    Then I put a subreport inside the pagestyle.
    This subreport got a pagestyle itself. This "subreport pagestyle" has
    the PageSetting = psFirstPage. In this pagestyle I put all the
    components, which shall appear on the first page only.

    The RTM file looks like this:
    ----------------------------
    object TppReport
    (...)
    object ppPageStyle1: TppPageStyle
    PageSetting = psFirstPage
    (...)
    [objects for all pages]
    object ppSubReport1: TppSubReport
    (...)
    object ppChildReport1: TppChildReport
    (...)
    object ppPageStyle74: TppPageStyle
    PageSetting = psFirstPage
    [objects for page No. 1 only]
    (...)
    end
    end
    end
    end
    (...)
    end
    ----------------------------

    My question:
    Is this solution a supported solution which will still work in future
    versions of ReportBuilder?

    Regards,
    David Bakker
  • edited March 2011
    Hi Stephan,

    Yes, this is definitely possible. You can use an event that fires
    before the page or band beings to do so. Ideally you would want to use
    the PageStyle.BeforePrint or Report.OnPageStart event to toggle the
    visibility of components in the band based on the PageNo.


    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited March 2011
    Hi David,

    Thanks for the explanation, I had originally thought that you wanted to
    toggle the entire contents of the page style for the first and
    subsequent pages. Your method below seems to be functioning within the
    design of ReportBuilder so it will be supported in the future.

    Another option of course would be to do without the subreport and simply
    toggle the visibility of the specific components that do not belong on
    certain pages as I described in my post to Stephan.


    Regards,

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

    Best Regards,

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