Skip to main content

Overview

TVirtualDBData is a virtual data class that links TDataSet or TDataSource fields to a TeeGrid. It provides automatic integration with database components, allowing seamless display and editing of database records.
Setting the TeeGrid DataSource property to a TDataSet or TDataSource component will automatically create a TVirtualDBData object.

Usage

Automatic Creation

The simplest way to use TVirtualDBData is to assign a dataset or data source directly to the grid:

Manual Creation

You can also manually create and configure a TVirtualDBData instance:

Types

TVirtualFetchMode

Controls how records are fetched from the dataset:
  • Automatic - Automatically determines fetch strategy based on dataset characteristics
  • All - Fetches all records at once
  • Partial - Fetches records on-demand (virtual mode)

Properties

TDataSet
Provides read-only access to the underlying TDataSet being displayed in the grid.
TVirtualFetchMode
default:"Automatic"
Controls the record fetching strategy. Set to All for smaller datasets or Partial for large datasets to improve performance.
Boolean
Determines whether the TVirtualDBData instance owns and will free the associated dataset. Set to True if you want the data adapter to manage the dataset’s lifetime.

Methods

Class Methods

class function
Creates a TVirtualData instance from a TComponent (TDataSet or TDataSource).Signature:
Parameters:
  • ASource - A TDataSet or TDataSource component
Returns: A new TVirtualDBData instance configured for the given data source.Example:
Links a TeeGrid column to a specific TField from the dataset.Signature:
Parameters:
  • AColumn - The TColumn to link
  • AField - The TField to link to the column
Example:

Instance Methods

procedure
Automatically adds columns to the grid based on the dataset fields.Signature:
Parameters:
  • AColumns - The columns collection to populate
Example:
function
Retrieves the floating-point value of a cell.Signature:
Parameters:
  • AColumn - The column to read from
  • ARow - The row index
Returns: The cell value as a floating-point number.
function
Retrieves the string representation of a cell value.Signature:
Parameters:
  • AColumn - The column to read from
  • ARow - The row index
Returns: The cell value as a string.
function
Returns the total number of rows (records) in the dataset.Signature:
Returns: The number of records in the dataset.
function
Returns the RTTI type information for a column’s data type.Signature:
Parameters:
  • AColumn - The column to query
Returns: Pointer to the type information for the column’s field type.
procedure
Loads or reloads the grid columns from the dataset.Signature:
Parameters:
  • AColumns - The columns collection to load into
function
Determines if a column is read-only based on the field properties.Signature:
Parameters:
  • AColumn - The column to check
Returns: True if the column’s field is read-only, False otherwise.
procedure
Sets a cell value, updating the underlying dataset field.Signature:
Parameters:
  • AColumn - The column to update
  • ARow - The row index
  • AText - The new value as a string
Example:
function
Calculates the optimal column width based on the data and painter.Signature:
Parameters:
  • APainter - The painter used for measuring text
  • AColumn - The column to measure
Returns: The calculated optimal width in pixels.
procedure
Called when the grid enters or exits edit mode.Signature:
Parameters:
  • AMode - The edit mode state
procedure
Refreshes the grid data from the dataset.Signature:
Example:

Complete Examples

Basic Database Grid

Advanced Configuration

Master-Detail Grids

Custom Field Linking

See Also