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

Add Rows to the Rowset Object

At this point, you have created a CDO Rowset object, added fields to the Rowset, and collected data in an array that will become part of a virtual runtime database. All that is left is to pass the data from the array to the Rowset object. This step is handled with a single method:

CDOSet.AddRows Rows

The AddRows method accepts a two-dimensional array containing the values you want added to the Rowset and, ultimately, added to a report file that is printed or exported. A one-dimensional array is used to add a single row with multiple fields.

Rows can be added to a CDO Rowset with multiple calls to the AddRows method. However, once you begin adding rows of data to a Rowset, you can not add any new fields to the Rowset. Any call to AddFields after a successful call to AddRows will fail.

Once you finish populating your virtual database in the CDO Rowset object, you can pass this object as an active data source to the Active Data Driver using the SetPrivateData method in the Crystal Report Engine Automation Server. For complete instructions on doing this, see Pass the Recordset to the Active Data Driver, Page 122.

Crystal Data Object Model

Crystal Data Objects support several methods and properties that can be used to work with the Rowset object. The object model for CDO is completely defined and described in the section Crystal Data Objects, Volume 3, Chapter 3.

Crystal Data Source Type Library

The Crystal Data Source Type Library, like Crystal Data Objects, provides a means for designing customized data sources that can be reported off of using the Active Data Driver. Crystal Data Source, however, unlike CDO, is a type library with an interface that can be implemented in a standard Visual Basic class. Once implemented, the Crystal Data Source interface allows your data to be fully manipulated much like a standard Recordset object in ADO or DAO.

NOTE: The Crystal Data Source type library is designed for Visual Basic 5.0 or later.

If you simply need a quick means for packaging some data in a form that can easily be reported off of, you should consider using Crystal Data Objects. Crystal Data Source, on the other hand, is designed for developers who need more flexibility when working with custom data sources. Keep in mind, though, once you add the Crystal Data Source interface to your class, you must implement all methods and properties exposed by the interface.

Visual Basic Solutions

131

The following topics are discussed in this section.

Creating a new project and class, Page 132

Adding the type library, Page 134

Implementing the functions, Page 135

Passing the CRDataSource object to the Active Data Driver, Page 137

Crystal Data Source Projects, Page 139

Creating a new project and class

The Crystal Data Source interface can be implemented inside almost any type of application. You might want to create and internal data source, for instance, inside the same standard executable application that you are implementing the Crystal Designer Component or the Automation Server. On the other hand, you could create an ActiveX DLL that did nothing except implement Crystal Data Source. Your ActiveX DLL then could work as a separate data source to be accessed from other applications, much like ADO, RDO, and DAO are used.

The following topics are discussed in this section.

When to use the Crystal Data Source Type Library, Page 132

Creating a new project, Page 132

Adding a class module to a project, Page 133

Adding a Sub Main() procedure, Page 133

When to use the Crystal Data Source Type Library

The Crystal Data Source interface, as stated before, is designed to allow developers to create full-fledged data sources that work much like the ADO Recordset object. In fact, the interface has been designed to support properties and methods with names identical to several corresponding properties and methods in the ADO Recordset object. Through your existing knowledge of ADO, you can quickly familiarize yourself with the Crystal Data Source interface.

If you are designing an application or component that must produce a fully featured data source with methods and properties for easily navigating through records and fields, Crystal Data Source is the ideal solution. Not only is the interface easy to learn and use, it also follows a Recordset standard currently being developed by Microsoft.

Creating a new project

For this tutorial, you will implement the Crystal Data Source interface in an ActiveX DLL that can be referenced by other applications. One such application may be a standard executable that uses the Active Data Driver with the Crystal Designer Component or the Crystal Report Engine to produce reports based on this new ActiveX data source.

Visual Basic Solutions

132

1With Visual Basic running, select New Project from the File menu. The New Project dialog box appears.

2Select ActiveX DLL from the New Project dialog box, and click OK. Your new ActiveX DLL project is created.

3Select Class1 in the Project window, and make sure the Properties window is displayed. To display the Properties window, press the F4 key or select Properties Window from the View menu.

NOTE: If you are not creating an ActiveX DLL, you may not have a class module in your project. See the next section, Adding a class module to a project.

4Change the value of the (Name) property for Class1 to MyDataSource.

5Select Project1 in the Project window, and change the value of the (Name) property for Project1 to

MyDataSourcePrj.

6Save the project. Use MyDataSource as the name of the class file and the project file.

Adding a class module to a project

Since you are creating an ActiveX DLL, your project already contains a class module that we can use to implement the Crystal Data Source interface. However, if you are creating a project that does not automatically include a class module, such as a Standard EXE project, you will need to use the following steps.

1.From the Project menu, select the Add Class Module command. The Add Class Module dialog box appears.

2.Make sure Class Module is selected, and click Open. The new class module is added to your project, and the code window for the module appears.

Adding a Sub Main() procedure

Although a Sub Main() procedure is not required by ActiveX DLLs created in Visual Basic 5.0 or later, you may want to create a Sub Main() procedure to handle initialization processes. Developers working in Visual Basic 4.0 are required to add the Main subroutine to an Automation Server DLL project and specify that the project use Sub Main() as the entry point. If you are creating an ActiveX EXE in Visual Basic 4.0 or later, you should add the Sub Main() procedure to allow your code to determine if it is being started as a stand-alone application or as an out-of-process automation server.

The following steps demonstrate how to add a Sub Main() procedure in Visual Basic versions 5.0 and 6.0. If you add this procedure to the MyDataSource project, you can leave the procedure empty.

1.From the Project menu in Visual Basic, select the Add Module command. The New Module dialog box appears.

2.Leave the default Module type selected, and click Open. A new module, Module1, is added to your project.

3.In the code window for the new module, add the following code:

Sub Main() End Sub

Visual Basic Solutions

133

Adding the type library

The Crystal Data Source interface is a standard COM (Component Object Model) interface that is defined in a type library (.TLB) file. To implement the Crystal Data Source interface in your Visual Basic application, you must first add a reference to the type library, implement the interface in your class module with the Implements statement, and, finally, create code for each of the properties and methods defined by the interface.

The following topics are discussed in this section.

Adding a reference to the Crystal Data Source Type Library, Page 134

Viewing in the Object Browser, Page 134

Using Implements in the class declaration, Page 135

Adding a reference to the Crystal Data Source Type Library

If this is the first time you are using the Crystal Data Source type library, you may need to tell Visual Basic where the type library is located before you can add a reference.

1From the Project menu, select the References command. The References dialog box appears.

2Scroll through the Available References list to locate the CRDataSource 1.0 Type Library. If you find the reference, skip to step 6. Otherwise, continue with the next step.

3In the References dialog box, click the Browse button to locate the type library file. The Add Reference dialog box appears.

4Locate the CRSOURCE.TLB type library file in the same directory that you installed Seagate Crystal Reports. If you accepted the default directory when you installed the product, this directory will be C:\Program Files\Seagate Software\Crystal Reports.

5Select CRSOURCE.TLB, and click Open. CRDataSource 1.0 Type Library will now appear in the Available References list in the References dialog box.

6Place a check mark in the check box next to CRDataSource 1.0 Type Library if one does not appear already.

7Click OK to add the reference to your project.

Viewing in the Object Browser

Before continuing with the design of your ActiveX DLL project, it may be helpful to look at the object model provided by the Crystal Data Source interface.

1From the View menu, select the Object Browser command. The Object Browser appears.

2Switch the Object Browser to display just the CRDataSourceLib object library.

Notice that the Crystal Data Source interface contains a single object: CRDataSource. This object is similar to the Recordset object you would see if you added a reference to the Microsoft ActiveX Data Objects Recordset 2.0 Library to your project. This is also the object you would pass to the Active Data Driver (Page 306) when producing a report at runtime.

Take a moment to review the properties and methods provided by the CRDataSource object. Close the Object Browser when finished.

Visual Basic Solutions

134

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