Consultor Eletrônico



Kbase P55350: How to display a Crystal report via 4GL using the Crystal Report Viewer ActiveX Control
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   07/09/2007
Status: Verified

GOAL:

How to use the Crystal Reports 9 Runtime Engine in 4GL

GOAL:

How to use the Crystal Reports 10 Runtime Engine in 4GL

GOAL:

How to use the Crystal Reports 11 Runtime Engine in 4GL

GOAL:

How to use the Crystal Report Viewer Control

GOAL:

How to use the Crystal ActiveX Report Viewer Control

GOAL:

How to display a Crystal report via 4GL

GOAL:

How to display a Crystal Reports XI report using 'CrystalActiveXReportViewer' Control version 11 and 4GL?

GOAL:

How to use the LogOnServer method to connect to a database when displaying a Crystal report via 4GL?

GOAL:

How to use the ConnectionProperties collection to connect to a database when displaying a Crystal report via 4GL?

FACT(s) (Environment):

Progress 8.3E
Progress 9.1D
Progress 9.1E
OpenEdge 10.x
Crystal Reports 9
Crystal Reports 10
Crystal Reports 11 (XI)
Windows

FIX:

1) Start AppBuilder and create a new window

2) Click the OCX button in the AppBuilder Palette and add the appropriate viewer control depending upon the version of Crystal Reports that is being used:

Crystal Report Viewer Control 9 - Crystal Reports 9
Crystal ActiveX Report Viewer Control 10.0 - Crystal Reports 10
Crystal ActiveX Report Viewer Control 11.0 - Crystal Reports 11

3) Add a button, copy the following code into the CHOOSE trigger of the button; the sections of the code that need to be replaced have been highlighted.

Please be aware that the default name of the control changes between Crystal Reports 9 and Crystal Reports 10/11.
For Crystal Reports 9, replace <Control Name> with CRViewer9
For Crystal Reports 10 or Crystal Reports 11, replace <Control Name> with CrystalActiveXReportViewer


Option #1 - ConnectionProperties

/* Sample Code - ConnectionProperties - Crystal Reports Viewer Control */
DEFINE VARIABLE chApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chReport AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chConnProps AS COM-HANDLE NO-UNDO.

CREATE 'CrystalRuntime.Application' chApplication.
CREATE 'CrystalRuntime.Report' chReport.

/* Insert full path to the Crystal report */
chReport = chApplication:OpenReport("<FullPathToReport>").

/* Set the Connection Info to Connection Properties of the table object */
chConnProps = chReport:Database:Tables(1):ConnectionProperties.

/* Clear the ConnectionProperties collection */
chConnProps:DeleteAll.

/* Add the ODBC DSN */
chConnProps:ADD("DSN", "<ODBC DSN Name>").

/* Add the database level User ID if required */
chConnProps:ADD("User ID", "<Username>").

/* Add the database level password if required */
chConnProps:ADD("Password", "<Password>").

/* Use either of the following statements to override the Catalog name if the report has been created using OpenEdge 10.1B or later - see P122620 for more information*/
/* chReport:Database:Tables(1):Location = "<Database Name>". */
/* chReport:Database:Tables(1):SetTableLocation("<Database Name>","",""). */

/* Example of some adjustable parameters */
chCtrlFrame:<Control Name>:EnableNavigationControls = TRUE. /* Enables the CRViewer's Navigation Controls */
chCtrlFrame:<Control Name>:EnableExportButton = TRUE. /* Enables the CRViewer's Export button */
chCtrlFrame:<Control Name>:EnableSearchControl = FALSE. /* Disables the CRViewer's Search control */

/* Set the report source */
chCtrlFrame:<Control Name>:ReportSource = chReport.

/* View the report */
chCtrlFrame:<Control Name>:ViewReport().

RELEASE OBJECT chConnProps.
RELEASE OBJECT chReport.
RELEASE OBJECT chApplication.

ASSIGN chConnProps = ?
chReport = ?
chApplication = ?
.


O.ption #2 - LogOnServer

/* Sample Code - LogOnServer - Crystal Reports Viewer Control */
DEFINE VARIABLE chApplication AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE chReport AS COM-HANDLE NO-UNDO.

CREATE 'CrystalRuntime.Application' chApplication.
CREATE 'CrystalRuntime.Report' chReport.

/* Enter details of your ODBC connection here */
chApplication:LogOnServer("CRDB_ODBC.DLL", "<ODBC DSN Name>", "", "<Username>", "<Password>").

/* Insert full path to the Crystal report */
chReport = chApplication:OpenReport("<FullPathToReport>").

/* Use either of the following statements to override the Catalog name if the report has been created using OpenEdge 10.1B or later - see P122620 for more information*/
/* chReport:Database:Tables(1):Location = "<Database Name>". */
/* chReport:Database:Tables(1):SetTableLocation("<Database Name>","",""). */

/* Example of some adjustable parameters */
chCtrlFrame:<Control Name>:EnableNavigationControls = TRUE. /* Enables the CRViewer's Navigation Controls */
chCtrlFrame:<Control Name>:EnableExportButton = TRUE. /* Enables the CRViewer's Export button */
chCtrlFrame:<Control Name>:EnableSearchControl = FALSE. /* Disables the CRViewer's Search control */

/* Set the report source */
chCtrlFrame:<Control Name>:ReportSource = chReport.

/* View the report */
chCtrlFrame:<Control Name>:ViewReport().

RELEASE OBJECT chReport.
RELEASE OBJECT chApplication.

ASSIGN chReport = ?
chApplication = ?
..