Skip to main content

Overview

The Tee.GridData.Rtti unit provides several classes to automatically link TeeGrid with records, objects, arrays, and generic collections using Delphi’s RTTI (Runtime Type Information) system.
These classes use reflection to automatically discover and bind to record fields and class properties, eliminating the need for manual column setup.

Classes

TVirtualDataRtti

Base class that provides RTTI-based data binding functionality. Typically not used directly.

TVirtualData<T>

Generic class that binds to any type using RTTI. This is the most flexible adapter and can handle:
  • Single records or objects
  • TArray<T> - Dynamic arrays
  • TList<T> - Generic lists
  • TObjectList<T> - Object lists

Helper Classes

For convenience, the following type aliases are provided:
  • TVirtualArrayData<T> - Alias for TVirtualData<TArray<T>>
  • TVirtualArray2DData<T> - Alias for TVirtualArrayData<TArray<T>>
  • TVirtualListData<T> - Alias for TVirtualData<TList<T>>
  • TVirtualObjectListData<T> - Alias for TVirtualData<TObjectList<T>>

TVirtualData<T> Constructor

constructor
Creates a new TVirtualData instance for the specified data.Signature:
Parameters:
  • AData - Reference to the data to bind (array, list, record, or object)
  • AVisibility - Which member visibility levels to include (default: public and published)
  • AMembers - Whether to include fields, properties, or both (default: both)
  • AAncestor - Whether to include ancestor class members (default: false)
Example:

TBaseVirtualData Constructor (Advanced)

constructor
Creates a data adapter from an object’s property (available only with NEWRTTI support).Signature:
Parameters:
  • AObject - The object containing the property
  • AProperty - Name of the property to bind
  • ACount - Fixed count (for array-like properties)
  • AVisibility - Which member visibility levels to include
  • AMembers - Whether to include fields, properties, or both
  • AAncestor - Whether to include ancestor class members

Types

TVisibility

Set of member visibility levels:

TRttiMembers

Specifies which RTTI members to include:
  • Both - Include both fields and properties
  • Fields - Include only fields
  • Properties - Include only properties

Methods

AddColumns

procedure
Automatically adds columns based on the type’s RTTI information.Signature:
Parameters:
  • AColumns - The columns collection to populate

AsFloat

function
Retrieves a cell value as a floating-point number.Signature:
Parameters:
  • AColumn - The column to read from
  • ARow - The row index
Returns: The cell value as a floating-point number.

AsString

function
Retrieves a cell value as a string.Signature:
Parameters:
  • AColumn - The column to read from
  • ARow - The row index
Returns: The string representation of the cell value.

Count

function
Returns the number of rows (array/list items).Signature:
Returns: The number of items in the array or list.

DataType

function
Returns the RTTI type information for a column.Signature:
Parameters:
  • AColumn - The column to query
Returns: Pointer to the type information.

SetValue

procedure
Sets a cell value, updating the underlying array or list item.Signature:
Parameters:
  • AColumn - The column to update
  • ARow - The row index
  • AText - The new value as a string

Usage Examples

Binding to Arrays

Binding to TList

Binding to Object Lists

Binding to Single Records

Controlling Visibility

Fields vs Properties

2D Arrays

Including Ancestor Members

Type Support

The RTTI data adapters automatically handle these types:
  • Numeric types: Integer, Int64, Single, Double, Currency
  • String types: string, AnsiString, WideString
  • Boolean types: Boolean, ByteBool, WordBool, LongBool
  • Date/Time types: TDate, TTime, TDateTime
  • Enumerated types: Displayed as their string names
  • Set types: Displayed as comma-separated values

Performance Considerations

RTTI-based binding uses reflection, which has some performance overhead. For extremely large datasets (100,000+ rows) with frequent updates, consider using custom virtual data classes instead.
However, for most applications with datasets under 50,000 rows, the performance is excellent and the convenience is worth it.

See Also