Overview
TVirtualData is an abstract base class that defines the interface for providing data to TeeGrid. It acts as a bridge between the grid and various data sources including databases, arrays, lists, and custom data structures.Concrete Implementations
TeeGrid includes several ready-to-use TVirtualData implementations:TVirtualDBData
Unit:
Tee.GridData.DBConnect to TDataSet and TDataSource for database data.TVirtualArrayData<T>
Unit:
Tee.GridData.RttiUse TArray<T> or TList<T> with RTTI for generic data.TVirtualStringData
Unit:
Tee.GridData.StringsString grid with Cells[Col, Row] interface like TStringGrid.TBIGridData
Unit:
BI.GridDataConnect to TeeBI TDataItem data structures.Abstract Methods
These methods must be implemented in descendant classes.
Required Data Methods
function
Returns the total number of rows in the data source.Signature:Returns: Total row count
function
Returns the string representation of data at the specified column and row.Signature:Parameters:
AColumn- The column to readARow- The row index (0-based)
procedure
Updates the value at the specified column and row.Signature:Parameters:
AColumn- The column to updateARow- The row index (0-based)AText- New value as string
Column Management
procedure
Automatically creates and adds columns to the grid based on the data structure.Signature:Parameters:
AColumns- The columns collection to populate
procedure
Loads or refreshes column metadata from the data source.Signature:Parameters:
AColumns- The columns collection to load
function
Calculates the optimal width for a column based on its content.Signature:Parameters:
APainter- Painter for measuring textAColumn- Column to measure
State Methods
function
Checks if the data source is empty.Signature:Returns: True if no data is available
function
Indicates whether the total row count is known in advance.Signature:Returns: True if Count returns an accurate value, False if the count is unknown or approximate
Virtual Methods
These methods have default implementations but can be overridden for custom behavior.
Data Access
function
Returns the numeric value of data at the specified column and row.Signature:Returns: Numeric value (default implementation converts AsString to float)
function
Returns type information for the specified column.Signature:Returns: Pointer to RTTI type information, or nil if unknown
Editing
procedure
Notifies the data source about edit mode changes.Signature:Parameters:
AMode- Edit mode:Start,Cancel, orFinish
function
Determines if a column is read-only.Signature:Returns: True if the column cannot be edited
procedure
Toggles a boolean value at the specified location.Signature:
Master-Detail
function
Checks if a row has expandable detail data.Signature:Returns: True if the row can be expanded to show detail grid
function
Creates and returns a TVirtualData instance for detail data.Signature:Parameters:
ARow- Master row indexAColumns- Columns for the detail gridAParent- Returns the parent column for the relationship
Expansion
function
Determines if a row can be expanded.Signature:Returns: True if row expansion is supported
Sorting
function
Checks if sorting by a column is supported.Signature:Returns: True if the column can be sorted
procedure
Sorts data by the specified column.Signature:
function
Checks if data is currently sorted by a column.Signature:Parameters:
Ascending- Returns True if sorted ascending, False if descending
Calculations
function
Performs calculations on column data.Signature:Parameters:
AColumn- Column to calculateACalculation- Type:Count,Sum,Min,Max, orAverage
Sizing
function
Calculates optimal height for a cell with multi-line content.Signature:Returns: True if auto-height was calculated
function
Measures the longest string in a column for auto-width calculation.Signature:Returns: Width of longest string in pixels
State Management
function
Checks if a row index is beyond the end of data.Signature:Returns: True if row index exceeds available data
Events and Callbacks
Protected Event Triggers
procedure
Triggers the OnRefresh event to notify the grid of data changes.Signature:
procedure
Triggers the OnRepaint event to request a visual update.Signature:
procedure
Notifies that a specific row’s data has changed.Signature:
procedure
Notifies about editing state changes.Signature:
Event Properties
TNotifyEvent
Fired when data needs to be refreshed from the source.
TNotifyEvent
Fired when the grid needs to be repainted.
TRowChangedEvent
Fired when the current row changes.Signature:
TDataEditingEvent
Fired when editing starts or stops.Signature:
Class Methods
class function
Factory method to create appropriate TVirtualData instance from a component.Signature:Returns: TVirtualData instance or nil if source is not supported
class function
Checks if a column contains numeric data.Signature:Returns: True for numeric data types
Example: Custom TVirtualData Implementation
Registration
Register custom TVirtualData classes to enable automatic detection:See Also
TTeeGrid
Main grid component
TCustomTeeGrid
Abstract base grid class
