Conditionally printing a page.

edited November 2012 in FastReport 4.0
I have a report where I would like a page to be conditionally printed. If a report is being printed for a certain Client ID, print a signature page for example else don't. I naturally think assigning visible to False in the page's BeforePrint would do the trick, but it doesn't.

If function TfrxEngine.CanShow(Obj: TObject; PrintIfDetailEmpty: Boolean): Boolean; would check the page's visibility, it would work. I think the workaround is to setting PrintIfEmpty to False and making sure the page is empty might work.

Any other ideas?

Comments

  • edited 8:04AM
    Make 2 reports, only print report 1 but if report 2 is also required you merge them into one.
  • edited 8:04AM
    technisoft wrote: »
    Make 2 reports, only print report 1 but if report 2 is also required you merge them into one.
    That would be possible, but the application design constraints are this:
    1. The application executes a report file passing a single parameter value of what to print.
    2. The core of the report is a document. The document may require a signature page or cover sheet. FR makes it easy to design pages which implement those items, but how can one surpress the printing of the other pages conditionally?

    Honoring the Visible property of the page object just as the Visible property of the band and layout objects are honored seems to be a logical solution FR does not implement for some reason.
  • edited 8:04AM
    kamiller42 wrote: »
    kamiller42 wrote: »
    Make 2 reports, only print report 1 but if report 2 is also required you merge them into one.
    That would be possible, but the application design constraints are this:
    1. The application executes a report file passing a single parameter value of what to print.
    2. The core of the report is a document. The document may require a signature page or cover sheet. FR makes it easy to design pages which implement those items, but how can one surpress the printing of the other pages conditionally?

    Honoring the Visible property of the page object just as the Visible property of the band and layout objects are honored seems to be a logical solution FR does not implement for some reason.

    You can change the visible property from event, but the Page's own OBP event is not the place to do it. In my experience you should always put your code above the component you want to alter.

    You can use one of theese:
    - Report.OnStart Report
    - OnBefore/AfterPrint of a previous page
    - the main code area of the report.

    Petter
  • edited 8:04AM
    gavind wrote: »
    Thanks for the suggestions. Which of the three you think is the best option for a beginner. I mean that would be the easiest route.

    My personal favorite is the main code area, if I have my conditions readable at this point (i.e. I pass the information to the report through a parameter). Easy to find, easy to maintain.

    But, be aware when using main code area that the report's data-components on the data-page (SQL or table) haven't been executed yet, so if you need to read from them you should open and move into them by code.

    If the page in question is the first page, the previous page-approach is obviously no good...

    I've never used the OnStartReport myself, but i tested it for this case, and it does the trick.

    Petter

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.