Conditionally printing a page.
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?
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
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
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