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

Changing OLE object images

OLE provides the means for incorporating many diverse file formats within your report. One of the most common and most valuable types of formats is images. However, data can change or be changed in a report, and images should reflect changes in data. It may be necessary to replace an OLE image with a new image at runtime.

The OLE Object provides the FormattedPicture property for getting and setting the current image displayed in an OLE object. This property can only be accessed during the Format event for the report Section containing the OLE image object.

The following examples demonstrate how to use the FormattedPicture property:

Private Sub Section1_Format(ByVal pFormattingInfo As Object)

Set Picture1.FormattedPicture = LoadPicture(“Xtreme.bmp”)

End Sub

NOTE: That if the image changes, the picture must be reloaded. OLE image controls can be assigned bitmaps (bmp), Windows metafiles (wmf), JPEG files (jpg), GIF files (gif), Icons (ico), and enhanced metafiles (emf).

NOTE: If you are familiar with COM interfaces, the FormattedPicture property can be assigned any image format that supports the IPictureDisp interface. Simply assign an instance of the interface to the property. Refer to the documentation that came with your image format tools to determine if the IPictureDisp interface is supported.

Working with Sections

All report objects, such as Fields and Text objects, are contained within Sections. Often, these can be obtained directly by referring to the name property of an object in your code. However, there may be times when you need to obtain an object through the report section it is in. For example, you may need to iterate through all objects in a section. At other times, you may have a need to make changes to the section itself.

Every report contains a collection of its sections, stored in the Sections property of the report object. Individual sections can be accessed through this collection. For example, the code below sets the height of the first section of the report (the Report Header) to half an inch (720 twips) and suppresses the second section of the report (the Page Header) so that it will not appear.

Dim Report As New CrystalReport1

Report.Sections.Item(1).Height = 720

Report.Sections.Item(2).Suppress = True

For information on how to obtain and work with other objects within a Section object, such as fields and text objects, refer to Working with the ReportObjects collection.

The Report Designer Component

182

Working with the ReportObjects collection

The ReportObjects collection of a report Section object contains all report objects in that section. Report objects may be Text objects, Fields, Subreport objects, or Crosstabs. To be able to work with a particular report object, you must first obtain the object, then you must determine what type of object it is.

Usually, report objects can be addressed directly in your code based on their Name property. However, if you intend to work with several objects in a section, you may need to refer to them through a Section object in the report. The following code locates the last object in the last section of the report and assigns a value to a String variable based on the type of object it is.

Dim Report As New CrystalReport1

Dim sect As Section

Dim rptObject As Object

Dim objKind As String

Dim lastSectWithObject As Integer

lastSectWithObject = Report.Sections.Count

Set sect = Report.Sections.Item(lastSectWithObject) Do While sect.ReportObjects.Count <= 0

lastSectWithObject = lastSectWithObject - 1

Set sect = Report.Sections.Item(lastSectWithObject)

Loop

Set rptObject = sect.ReportObjects.Item(sect.ReportObjects.Count)

Select Case rptObject.Kind

Case crBlobFieldObject

objKind = “BLOB field object”

Case crBoxObject

objKind = “Box object”

Case crCrossTabObject

objKind = “CrossTab object”

Case crFieldObject

objKind = “Field object”

Case crGraphObject

objKind = “Graph object”

Case crLineObject

objKind = “Line object” Case crOleObject

The Report Designer Component

183

objKind = “OLE object”

Case crSubreportObject

objKind = “Subreport object”

Case crTextObject

objKind = “Text object”

Case Else

objKind = “Unknown object”

End Select

Working with the FieldObject object

All relational databases have two standard features: records and fields. Records contain the actual data, while fields define what type of data the records contain. Records are controlled through Recordset and Resultset objects exposed by ADO, RDO, and DAO. Through such interfaces, you can also manipulate the fields in the data source. However, to manipulate the fields that appear in your report, you must obtain a FieldObject from the Report Designer object model.

A FieldObject is a feature of your report, and is, therefore, obtained through the ReportObjects collection. You can query a specific report object to find out if it is a field, then work directly with the field, and even query it for its value. The sample code below locates the first database field that appears in a report then obtains information about that field.

Dim Report As New CrystalReport1

Dim rptObject As ReportObject

Dim fldObject As FieldObject

Dim dbFieldDef As DatabaseFieldDefinition

Dim message As String

‘ Locate the first field in the report For Each sect In Report.Sections

For Each rptObject In sect.ReportObjects

‘ Is it a field?

If rptObject.Kind = crFieldObject Then Set fldObject = rptObject

‘ Is it a database field?

If fldObject.Field.Kind = crDatabaseField Exit For

End If

End If

The Report Designer Component

184

Next

If fldObject.Field.Kind = crDatabaseField Then

dbFieldDef = fldObject.Kind Exit For

End If

Next

message = “The first database field in the report is: “ & _ dbFieldDef.DatabaseFieldName

MsgBox message

Working with the SubreportObject object

A SubreportObject object is, essentially, another Report Object (see Report Object, Volume 3, Chapter 2), inside the original report. Once you have obtained a SubreportObject, you can work with any aspect of it just as if it were a standard Report object.

NOTE: You can not print, export, or display in the Smart Viewer a subreport outside of its primary report. The SubreportObject can be manipulated in any way that Report objects are, but they can only be printed, exported, or displayed as part of the primary report.

A SubreportObject is obtained through the ReportObjects collection. The following example shows how to iterate through the sections of a report and change the background color of each subreport to magenta.

Dim Report As New CrystalReport1

Dim subReport As SubreportObject

For Each sect In Report.Sections

For Each rptObject In sect.ReportObjects

If rptObject.Kind = crSubreportObject Then

Set subReport = rptObject subReport.BackColor = RGB(255, 0, 255) Set subReport = Nothing

End If

Next

Next

NOTE: Currently, the Seagate Crystal Report Designer Component does not support subreports inside of subreports. The report iterations can not go more than one subreport deep. However, you can have multiple subreports inside the main report.

For more information on working with the ReportObjects collection, see Working with the ReportObjects collection, Page 183.

The Report Designer Component

185

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