Crystal Reports in PowerBuilder. Rdc9 - Powerbuilder
Crystal Reports in PowerBuilder. Rdc9 - Powerbuilder
Crystal Reports in PowerBuilder. Rdc9 - Powerbuilder
Overview
This document describes how to create a PowerBuilder application using the Crystal Report Designer Component 9 (RDC). This document covers the basic properties and methods that would be used to create an application that prints, previews or exports a report. This document is for use with Crystal Reports 9.0 and higher.
Contents
INTRODUCTION ............................................................................................ 2 THE OBJECT MODEL ................................................................................... 2 USING REPORT FILES WITH THE RDC .......................................................... 2 Creating a Report file ..................................................................................3 Creating the PowerBuilder application .......................................................4
Add the Crystal Viewer Control ........................................................................ 4 Logon to the Database ....................................................................................... 5 Setting Parameters ............................................................................................. 5 Preview the Report............................................................................................. 6 Exporting the Report.......................................................................................... 6 Printing the Report............................................................................................. 7 Closing the Window .......................................................................................... 8
7/16/2004 8:52 AM
Page 1
Introduction
The RDC is supported in PowerBuilder as an OLEObject. Report development is achieved by accessing properties and methods through an object hierarchy. The Report Design Component (RDC) for use in PowerBuilder is composed of 2 primary DLLs: Craxdrt9.dll (Crystal Reports ActiveX Designer Runtime Library). This runtime library formats and populates the report with data from the database. This DLL needs to be included in the distribution of your compiled application. Crviewer9.dll (Crystal Reports Viewer Control Library). This ActiveX viewer control previews the report objects and can export or print the report from the viewer window. The crviewer9.dll also has an object model hierarchy.
NOTE
In Crystal Reports 10.0 the Crystal Reports ActiveX Designer Runtime Library will be CRAXDRT.dll and the Crystal Reports Viewer Control Library will be CRVIEWER.dll
7/16/2004 8:52 AM
Page 2
RDC9_PowerBuilder.pdf
You can modify and distribute the same application with different reports to provide flexible applications for multiple work environments. Distributing report files will increase the size of your application package.
"C:\Program Files\Crystal Decisions\Crystal Reports 9\Samples\En\Reports\General Business\Employee Profile.rpt" 3. This report is created against the default ODBC Data source that Crystal Reports installs, Xtreme Sample Database 9. There should be no password. Under File in the menu, uncheck Save Data with Report. To see the Field Explorer, choose View Field Explorer. Right click on Parameter Fields and choose New. Name the parameter Employee ID. Prompting text can be Enter the Employee ID. The value type is number. Choose OK. Under the Report Menu, choose Selection Formulas then Record. Expand the Report Fields. Double click on Xtreme Sample Database 9 and expand the Employee table. Double click on Employee ID. That will bring the {Employee.Employee ID} field down into the Formula box. Type =. Then expand the report fields the same way and double click on ?Employee ID. It will move down to complete the selection formula.
4. 5.
6.
7. 8.
Save and close the selection formula. Run the report to be sure it is successful. Save the report to: "C:\ Employee Profile.rpt" (or a path of your choice.)
Now that the report is saved as a disk file, you can set up a PowerBuilder project that will load this report into the Crystal Reports Viewer Control.
7/16/2004 8:52 AM
Page 3
RDC9_PowerBuilder.pdf
2.
3.
global variables OLEObject g_ole_crx_application OLEObject g_ole_crx_report OLEObject g_ole_crx_connection_info OLEObject g_ole_crx_export_options
4.
Again click File and this time choose New PB Object. From the dialog box choose a Window object. In the Properties box, title the Window object crPreview. Save the Window object as w_crpreview.
6. 7.
gi_return = g_ole_crx_application.ConnectToNewObject('CrystalRuntime.Ap plication.9') if gi_return < 0 then MessageBox("Error", "Did not connect to Crystal Application Object") return
7/16/2004 8:52 AM
Page 4
RDC9_PowerBuilder.pdf
end if
8.
Use the Application object to load the report. OpenReport takes the full path to the report and "1" to open it as a temporary copy rather exclusively.
g_ole_crx_report = g_ole_crx_application.OpenReport(gs_rpt_filename, 1)
10. Then add the new connection properties. For the report we created we need only the DSN property. The database remains unchanged from the report.
g_ole_crx_connection_info.add("DSN", "Xtreme Sample Database 9")
For other types of connection where there is a database schema and security you would need the DSN, the Database, User ID and Password properties
g_ole_crx_connection_info.add("Database", "Xtreme") g_ole_crx_connection_info.add("User ID", "UID") g_ole_crx_connection_info.add("Password", "PWD")
11. Then verify the database to be sure Crystal sees the data as it is now and not as it was when the report was created.
g_ole_crx_application.database.Verify
Place four command buttons on the Window form. The first, title Set Parameters, the second Preview; the third, Export; and the fourth, Print.
Setting Parameters
Crystal Reports parameters will prompt for the value needed without any code being created. Once the application is complete, preview the report without clicking on the Set Parameter button and you will get the default prompt.
7/16/2004 8:52 AM
Copyright 2004 Business Objects. All rights reserved.
Page 5
RDC9_PowerBuilder.pdf
Place the code for the Report parameter field into the script behind Command Button 1. You can pass the parameter by the index of the field in the order it appears in the designer.
g_ole_crx_application.ParameterFields[1].AddCurrentValue(3)
There is also a method to pass the parameter value by name using the GetItemByName property of the parameter field.
g_ole_crx_application.ParameterFields.GetItemByName("Employ ee ID").AddCurrentValue(4)
ole_crviewer.object.ReportSource(g_ole_crx_application )
2.
Set crviewer properties. In this case, set a print button and an export button visible on the preview window.
3.
ole_crviewer.object.ViewReport
g_ole_crx_export_options = g_ole_crx_application.ExportOptions
7/16/2004 8:52 AM
Page 6
RDC9_PowerBuilder.pdf
2.
3.
g_ole_crx_export_options.DestinationType = 1 // crEDTDiskFile
4.
g_ole_crx_export_options.FormatType = 31 //crEFTPortableDocFormat
5.
g_ole_crx_export_options.PDFExportAllPages = True
6.
g_ole_crx_export_options.PDFFirstPageNumber = 2 g_ole_crx_export_options.PDFLastPageNumber = 3
7.
g_ole_crx_application.Export(False)
1.
To print to the printer setting specific properties at runtime, use the SelectPrinter method passing the printer driver, printer name and port name.
7/16/2004 8:52 AM
Page 7
RDC9_PowerBuilder.pdf
2.
Set any properties of the printer you want to use such as orientation or suppressing the dialog that lets you know a report is printing.
g_ole_crx_application.PaperOrientation = 2 g_ole_crx_application.DisplayProgressDialog = False 3. Once you have set the properties you need, print the report.
g_ole_crx_application.PrintOut(False, 1, True, 1, 2)
That will print page 1 and 2 of the report in landscape mode without a dialog to say the report is printing.
Caution
Crystal Reports uses the properties available in your printer driver to format the report. That may make a difference to the look of your report from client to client. For information on the influence of printer drivers see:
http://support.businessobjects.com/communityCS/TechnicalPapers/scrprinterde pendency.pdf.asp
Now the objects are released to be recreated for the next report.
Database Connectivity
CR_QUERY_ENGINE.pdf - This document provides information about the improvements to the query engine in Crystal Reports (CR) 9 as compared to version 8.5. This includes information about the differences in database architecture, the integrated Database Expert and new data source connections.
Printing
SCRPRINTERDEPENDENCY.pdf - This document discusses how you can design reports that print consistently across different computers. Includes workable solutions, tips, tricks, and design criteria to help you make use of the functionality of the Crystal Reports.
Knowledge Base article c2007185 Changing Paper Source and Paper Tray http://support.businessobjects.com/library/kbase/articles/c2007185.asp
7/16/2004 8:52 AM
Copyright 2004 Business Objects. All rights reserved.
Page 8
RDC9_PowerBuilder.pdf
Parameter Fields
RDCPARAM.pdf Using parameter fields in the Report Design Component (RDC).
Exporting
CR8_VB_RDC_EXPORT.pdf Exporting at runtime using Report Design Component (RDC). This is an older paper with good information but some properties are no longer valid in version 9.0. See CrystalDevHelp.chm to confirm the properties you are using.
www.businessobjects.com
The Business Objects product and technology are protected by US patent numbers 5,555,403; 6,247,008; 6,578,027; 6,490,593; and 6,289,352. The Business Objects logo, the Business Objects tagline, BusinessObjects, BusinessObjects Broadcast Agent, BusinessQuery, Crystal Analysis, Crystal Analysis Holos, Crystal Applications, Crystal Enterprise, Crystal Info, Crystal Reports, Rapid Mart, and WebIntelligence are trademarks or registered trademarks of Business Objects SA in the United States and/or other countries. Various product and service names referenced herein may be trademarks of Business Objects SA. All other company, product, or brand names mentioned herein, may be the trademarks of their respective owners. Specifications subject to change without notice. Not responsible for errors or omissions. Copyright 2004 Business Objects SA. All rights reserved.
7/16/2004 8:52 AM
Page 9
RDC9_PowerBuilder.pdf