Overview
TeeGrid uses an abstraction layer calledTVirtualData to connect to various data sources. This design allows the grid to work with databases, arrays, lists, and custom data sources through a unified interface.
The TVirtualData Abstract Class
TVirtualData is defined in Tee.GridData.pas and provides the contract that all data adapters must implement:
Key Methods
procedure
Populates the columns collection with columns representing the data structure (fields, properties, etc.).
function
Retrieves the display value for a specific cell. This is the most frequently called method during rendering.
function
Returns the total number of rows in the data source. Return -1 if the count is unknown (streaming data).
procedure
Associates existing columns with data source fields. Used when columns are defined manually rather than auto-generated.
procedure
Updates a cell value when the user edits it. Implement validation and data conversion here.
Built-in Data Adapters
TeeGrid provides several ready-to-use data adapters:Database Binding (TVirtualDBData)
Connects to TDataSet or TDataSource components:- Automatic column creation from dataset fields
- Native data type support (string, integer, float, date, etc.)
- Edit support with automatic dataset posting
- Master-detail relationships
- Filtering and sorting integration
Array and List Binding (TVirtualData<T>)
Connects to TArray<T> and TList<T> using RTTI:- Automatic column creation from public fields and properties
- RTTI-based value retrieval and setting
- Support for nested objects
- Configurable visibility levels (mvPublic, mvPublished)
- Edit support with automatic value conversion
String Grid Binding (TVirtualStringData)
Emulates a string grid with Cells[Col,Row] indexing:Data Binding Process
When you assign data to a grid, TeeGrid follows this sequence:1
Data Assignment
You set
TeeGrid.DataSource or TeeGrid.Data.2
Adapter Creation
If using DataSource, TeeGrid automatically creates the appropriate TVirtualData implementation based on the component type.
3
Column Generation
TeeGrid calls
TVirtualData.AddColumns() to populate the Columns collection automatically.4
Column Association
Each TColumn gets a TagObject linking it to the data source field or property.
5
Initial Render
The grid renders using
TVirtualData.AsString() to retrieve cell values.Automatic Column Generation
WhenAddColumns is called, the data adapter creates columns based on the data structure:
- Database Fields
- RTTI Members
- String Columns
Manual Column Configuration
You can define columns manually and then bind them to data:Data Events
TVirtualData provides events to notify the grid of changes:TNotifyEvent
Triggered when the data structure changes (columns added/removed, data reloaded).
TNotifyEvent
Triggered when data values change but structure remains the same.
TRowChangedEvent
Triggered when the current row changes.
TDataEditingEvent
Triggered when edit mode starts or ends.
Creating Custom Data Adapters
You can create custom TVirtualData implementations for specialized data sources:Performance Considerations
Lazy Loading
Lazy Loading
Only visible rows are rendered. The
AsString method is called only for cells currently displayed on screen.Value Caching
Value Caching
For expensive calculations, cache values in your TVirtualData implementation rather than recalculating on each
AsString call.Unknown Count
Unknown Count
Return -1 from
Count for streaming data. TeeGrid will fetch rows on-demand without requiring the total count upfront.AutoWidth Optimization
AutoWidth Optimization
Implement
AutoWidth efficiently - it’s called once per column but may be expensive if it scans all rows.Common Patterns
Read-Only Data
Calculated Columns
Data Validation
Registration System
TeeGrid includes a registration system for automatic adapter selection:DataSource, TeeGrid calls TVirtualDataClasses.Guess() to find a compatible adapter.
Next Steps
Virtual Data
Deep dive into TVirtualData implementations
Columns
Learn about the column system and hierarchy
Database Grids
Working with TDataSet and database components
Arrays & Lists
Binding to in-memory data structures
