Skip to main content

Overview

When built-in data classes don’t fit your needs, create a custom TVirtualData descendant. This gives you complete control over:
  • Data source and storage
  • Column generation and configuration
  • Cell value retrieval and editing
  • Performance optimization for your specific use case
All TeeGrid data sources inherit from TVirtualData. Understanding this base class unlocks the full power of the grid.

TVirtualData Base Class

The abstract base class that all data sources inherit from:

Minimal Implementation

Create a simple read-only data source:
Usage:

Editable Data Source

Add editing support:

Database-Backed Example

Create a custom data source that loads from a database:
The database example above is simplified. Production code should include:
  • Connection error handling
  • Transaction management
  • Caching for better performance
  • Proper SQL injection prevention

Computed Columns

Add calculated columns to your data:

Factory Method Pattern

Implement a From class method for easy instantiation:

Performance Optimization

Optimize for large datasets:
Performance Tips:
  • Override AutoWidth to return a fixed value (skip measurement)
  • Implement KnownCount to return True if you know the exact row count
  • Cache frequently accessed rows
  • Batch database queries
  • Use SetFirstRow to prefetch visible rows

Column Data Types

Provide type information for proper formatting:

Testing Your Custom Data

Unit test your implementation:

Real-World Examples

Check these demo units for inspiration:
  • Unit_VirtualMode.pas: Virtual mode with events (TeeGrid.GridData.Strings:80)
  • Unit_MyData.pas: Sample record and class definitions (TeeGrid.Demos:1)
  • Tee.GridData.DB.pas: Full dataset implementation (TeeGrid.GridData.DB:65)
  • Tee.GridData.Rtti.pas: RTTI-based array/list binding (TeeGrid.GridData.Rtti:64)

Next Steps

DataSet Binding

Study TVirtualDBData implementation

Arrays and Lists

See TVirtualData<T> RTTI binding

API Reference

Complete TVirtualData API documentation

Rendering

Custom cell rendering and painting