ComponentOne VSView Reporting Edition
FieldInfo Property

Returns a variant array containing all field names, types, and size for the current report data source.

Syntax

dataSource.FieldInfo[ = value As Variant ]

Remarks

This property is useful in designer-type applications that need to retrieve information about the fields available in the source recordset.

The difference between retrieving this information directly from the recordset or from the FieldInfo property is that the source recordset is open only while the report is rendering, while the FieldInfo is available at all times.

The array returned contains one row for each field. Each row contains three columns, with the field name, ADO data type, and size (in bytes).

The example below shows a simple use for the FieldInfo property:

Dim v, i%

v = vsr.DataSource.FieldInfo

Debug.Print "** Fields in '"; vsr.ReportName; "'"

Debug.Print "Field#", "Name", "Type", "Size"

For i = 0 To UBound(v, 1)

    Debug.Print "Field "; i,

    Debug.Print v(i, 0), v(i, 1), v(i, 2)

Next

 

** Fields in 'Alphabetical List of Products'

Field#        Name            Type          Size

Field  0      ProductID        3             4

Field  1      ProductName      202           40

Field  2      SupplierID       3             4

Field  3      CategoryID       3             4

Field  4      QuantityPerUnit  202           20

Field  5      UnitPrice        6             8

Field  6      UnitsInStock     2             2

Field  7      UnitsOnOrder     2             2

Field  8      ReorderLevel     2             2

Field  9      Discontinued     11            2

Field  10     CategoryName     202           15

The Report Designer uses this property extensively, to build field-pick lists and to automatically size report fields created by the New Report Wizard.

To use the FieldInfo property in Visual C++ programs, you need to use the system APIs designed to manipulate SAFEARRAY structures. The example below shows how that works:

// import interfaces for VSReports7 control

#import  "VSRpt8.ocx"    no_namespace

 

// use FieldInfo to get field information for a given report

BOOL ListFields(IVSReportPtr spReport)

{

    USES_CONVERSION;

 

    // get data source

    if (spReport == NULL) return FALSE;

    IDataSourcePtr spDS = spReport->DataSource;

    if (spDS == NULL) return FALSE;

 

    // get FieldInfo array

    CComVariant v = spDS->FieldInfo;

    if (V_VT(&v) != (VT_ARRAY | VT_VARIANT)) return FALSE;

    ATLASSERT(v.parray->cDims == 2);

 

    // scan FieldInfo array and display the information

    long pIndex[2];

    for (long i = 0;; i++) {

 

        // reading array row I

        pIndex[0] = i;

 

        // get field name

        pIndex[1] = 0;

        CComVariant vName;

        CComBSTR    strName;

        if (FAILED(SafeArrayGetElement(v.parray, pIndex, &vName))) break;

        if (vName.vt == VT_BSTR) strName = V_BSTR(&vName);

 

        // get field type

        pIndex[1] = 1;

        CComVariant vType;

        if (FAILED(SafeArrayGetElement(v.parray, pIndex, &vType))) break;

 

        // get field size

        pIndex[1] = 2;

        CComVariant vSize;

        if (FAILED(SafeArrayGetElement(v.parray, pIndex, &vSize))) break;

 

        // show the information

        ATLTRACE("Field %d  %s  %d  %d\n",

                  i, W2T(strName), V_I4(&vType), V_I4(&vSize));

    }

 

    // done

    return TRUE;

}

The #import statement is very important. It loads all interfaces and constants defined by the control. The CComVariant, CComBSTR, USES_CONVERSION, and ATLTRACE symbols are defined by ATL. Other class libraries have similar constructs and classes (for example, MFC had COleVariant, CString, and TRACE).

Data Type

Variant

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback