Interface

DataSet


Description

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

Methods

Name

Parameters

Returns

Shared

EOF

Boolean

Field

idx As Integer

Variant

Name As String

Variant

NextRecord

Boolean

Run

Type

FieldName As String

Integer

Method descriptions


DataSet.EOF

EOF As Boolean

Specifies whether the end of file has been reached.


DataSet.Field

Field(idx As Integer) As Variant

Gets the field by name.


DataSet.Field

Field(Name As String) As Variant

Gets the field by name.


DataSet.NextRecord

NextRecord As Boolean

Advances to the next record.


DataSet.Run

Run

Run is the first method to be called when the report is run.


DataSet.Type

Type(FieldName As String) As Integer

Declares the field types for the data in the DataSet. Returns an Integer that indicates the data type.

The field types are the SQL field types listed in the Database.TableColumns entry. The reporting engine uses this to determine whether the column is numeric and whether the Format function should be applied.

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.

Sample code

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.

Sub Run()
  // Part of the Reports.DataSet interface.
  mData = Price_of_Gasoline.SplitBytes(String.ChrByte(13))
  mCurrentRecord = 0
End Sub

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")

  Var data() As String = mData(mCurrentRecord).SplitBytes(",")

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

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

  mCurrentRecord = mCurrentRecord + 1
End Sub

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

  Return False
End Sub

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

Compatibility

All projects types on all supported operating systems.