Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
81
Добавлен:
11.05.2015
Размер:
2.11 Mб
Скачать

Viewing the Crystal Report Engine Object Library

The Visual Basic Object Browser allows you examine the classes, methods, and properties exposed by any ActiveX component available to your project. If you have selected the Crystal Report Engine Object Library using the References dialog box (see Adding the Automation Server to your Visual Basic Project, Page 111), then you can browse through the Object Library using the Visual Basic Object Browser:

1With your project open in Visual Basic, choose OBJECT BROWSER from the View menu. The Object Browser appears.

2From the Libraries/Projects drop-down box, select the Crystal Report Engine Object Library. Classes, methods, and properties exposed by the Object Library will appear in the Object Browser.

3Select a class in the Classes/Modules list box to view its methods and properties in the Methods/ Properties list box.

NOTE: While viewing the Crystal Report Engine Object Library in the Visual Basic Object Browser, you may notice several classes, methods, and properties that are not documented in the Seagate Crystal Reports Technical Reference. There are several features in the Crystal Report Engine Automation Server that are not available with Seagate Crystal Reports, and are protected by a security feature built into the Object Library. These features will become available in future Seagate Software products. Contact Seagate Software’s Sales department for further information.

Seagate Crystal Reports also provides the Crystal Report Engine Object Library Browser Application as a convenient utility for accessing online information about the Crystal Report Engine Object Library. Simply choose the Xtreme Mountain Bike option in the Sample Files when installing, or choose an automatic installation (the files will be installed by default) to install the utility, then browse through the Object Library using the tree control. Select a class, method, or property for more information on how to use it.

Handling Preview Window Events

The Report and Window objects in the Crystal Report Engine Object Library include several Events. By handling these events in your Visual Basic project, you can customize how your application responds to user actions. For instance, if a user clicks on a button in the toolbar of the preview window, such as the Zoom button or the Next Page button, your application can respond to that event.

NOTE: Events are only available in Visual Basic 5.0 and later. If you are using a version of Visual Basic earlier than 5.0, you will not be able to make use of the Events exposed by the Report or Window object.

To handle Events for the Report or Window object, you must declare the instance of the object as Public and WithEvents. For example:

Public WithEvents repEvents As CRPEAuto.Report

Public WithEvents wndEvents As CRPEAuto.Window

Once declared, the objects will appear in the Visual Basic Object window. If you select the object, its Events will be displayed, just as if you were working with any other Visual Basic object.

Visual Basic Solutions

115

NOTE: The Window object events are only valid when a report is sent to a preview window using the Preview method.

The following code demonstrates how to set up and use events for both the Report object and the Window object. Actual event handling code is left for you to fill in. You are limited only by the restrictions of the Visual Basic language.

Option Explicit

Public WithEvents rpt1 As CRPEAuto.Report

Public vw1 As CRPEAuto.View

Public WithEvents wnd1 As CRPEAuto.Window

Private Sub Command1_Click()

Set vw1 = rpt1.Preview

Set wnd1 = vw1.Parent

End Sub

Private

Sub Form_Load()

Set

app1

=

CreateObject(“Crystal.CRPE.Application”)

Set

rpt1

=

app1.OpenReport(“c:\crw\rt01.rpt”)

rpt1.EventInfo.ActivatePrintWindowEventEnabled = True rpt1.EventInfo.ClosePrintWindowEventEnabled = True rpt1.EventInfo.GroupEventEnabled = True rpt1.EventInfo.PrintWindowButtonEventEnabled = True rpt1.EventInfo.ReadingRecordEventEnabled = True rpt1.EventInfo.StartStopEventEnabled = True

End Sub

Private Sub rpt1_Start(ByVal Destination As _ CRPEAuto.CRPrintingDestination, _ useDefault As Boolean)

' Put event handling code here.

End Sub

Private Sub rpt1_Stop (ByVal Destination As CRPEAuto.CRPrintingDestination,

ByVal Status As CRPEAuto.CRPrintingProgress)

'Put event handling code here. End Sub

Private Sub wnd1_ActivatePrintWindow()

'Put event handling code here. End Sub

Visual Basic Solutions

116

Private Sub wnd1_ClosePrintWindow (useDefault As Boolean)

' Put event handling code here.

End Sub

Other events for the Report and Window objects

can be seen by using the Visual Basic Object Browser

with the Crystal Report Engine Object Library.

(a lightning bolt icon appears next to Events in

the Object Browser.)

Once and instance of a Report object or Window object,

is declared, you can add Event handlers to your code by

selecting the object in the Visual Basic Object list and

then selecting the desired event.

For complete descriptions of all available Crystal Report Engine Object Library Events, refer to the Report Object, Volume 3, Chapter 2, and the Window Object, Volume 3, Chapter 6.

NOTE: In the previous version of Seagate Crystal Reports a report or window object variable declared WithEvents could only be Set once. A VB error occurred if you tried to Set the variable to a different value(i.e. access a new report or display a new Preview window). This problem no longer exists. You can now reset the values of WithEvent object variables.

Distributing the Automation Server with Visual Basic Applications

When you finish designing your application and decide to distribute it to your users, you must make sure that the Crystal Report Engine Automation Server is distributed with it. In addition, you must make sure the automation server gets registered on your users’ systems. The easiest way to do this is to use the Application Setup Wizard installed with Visual Basic.

This Wizard leads you through the process of designing a setup application for your project. In addition, the Setup Wizard detects any ActiveX components included in your project and leads you through the process of adding code to the setup application to include the required files and register the components on a user’s machine.

For more information about files that need to be distributed with Crystal Report Engine applications, refer to Runtime File Requirements online Help.

Sample Applications

Seagate Crystal Reports includes a complete sample application written in Visual Basic 5.0 using the Crystal Report Engine Automation Server. The Xtreme Mountain Bike Inventory Application is a complete real-world application that provides various reports to employees at a fictitious company. Report access is restricted based on user logon information. The application is located in \Program Files\Seagate Software\Crystal Reports\sample\Xtreme\Inventory and provides the option of viewing the source code for any Visual Basic form displayed.

Visual Basic Solutions

117

Соседние файлы в папке crystal