DataSet

From Xojo Documentation

Interface


A component of the Reports module that provides the data access for the report.

Methods
EOF NextRecord
Field Run
Field Type

Notes

The DataSet interface enables you to use any dataset as the data source for the report. See the example for notes on how to set up the DataSet interface to use a text file as the data source.

To return Pictures for display in a report, you should return the Picture data rather than a Picture object. For example, if you have a Picture in variable p, then your would return the Picture data in the Field method like this:

Return p.GetData(Picture.FormatPNG)

Use a type of 14 to identify the Picture as data.

Examples

See the Gas Report example project that is included with Xojo. This example uses a text file as the data source for the report. It was added to the project and is named "Price_of_Gasoline". The DataSet interface is used to make the data available to the reporting engine. The GasDataSet class implements the DataSet interface. The following methods are used.

Run

Sub Run()
// Part of the Reports.DataSet interface.
mData = SplitB(Price_of_Gasoline, ChrB(13))
mCurrentRecord = 0
End Sub

Field

Sub Field(Name As String) As Variant
// Part of the Reports.DataSet interface.
Static months() As String = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",_
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

Dim data() As String = SplitB(mData(mCurrentRecord), ",")

If name = "Year" Then
Return data(0)
Else
Dim idx As Integer = months.IndexOf(name)
If idx <> -1 Then Return data(idx + 1)
End If
Return Nil
End Sub

NextRecord

Sub NextRecord() As Boolean
// Part of the Reports.DataSet interface

mCurrentRecord = mCurrentRecord + 1
End Sub

EOF

Sub EOF() As Boolean
// Part of the Reports.DataSet interface.
If mCurrentRecord > mData.Ubound Then Return True

Return False
End Sub

Type

// Part of the Reports.DataSet interface
Function Type(fieldname As String) As Integer
If fieldname = "Year"
Return // Text
Else
Return 7 // Double
End if
End Function

See Also

Reports module; Report, ReportField, ReportLabel, ReportLineShape, ReportOvalShape, ReportRectangleShape, ReportRoundRectangleShape. ReportPicture classes; UserGuide:Displaying Desktop Reports topic