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 useTVirtualDBData is to assign a dataset or data source directly to the grid:
Manual Creation
You can also manually create and configure aTVirtualDBData instance:
Types
TVirtualFetchMode
Controls how records are fetched from the dataset:Automatic- Automatically determines fetch strategy based on dataset characteristicsAll- Fetches all records at oncePartial- Fetches records on-demand (virtual mode)
Properties
Provides read-only access to the underlying TDataSet being displayed in the grid.
Controls the record fetching strategy. Set to
All for smaller datasets or Partial for large datasets to improve performance.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
Creates a TVirtualData instance from a TComponent (TDataSet or TDataSource).Signature:Parameters:
ASource- A TDataSet or TDataSource component
Links a TeeGrid column to a specific TField from the dataset.Signature:Parameters:
AColumn- The TColumn to linkAField- The TField to link to the column
Instance Methods
Automatically adds columns to the grid based on the dataset fields.Signature:Parameters:
AColumns- The columns collection to populate
Retrieves the floating-point value of a cell.Signature:Parameters:
AColumn- The column to read fromARow- The row index
Retrieves the string representation of a cell value.Signature:Parameters:
AColumn- The column to read fromARow- The row index
Returns the total number of rows (records) in the dataset.Signature:Returns:
The number of records in the dataset.
Returns the RTTI type information for a column’s data type.Signature:Parameters:
AColumn- The column to query
Loads or reloads the grid columns from the dataset.Signature:Parameters:
AColumns- The columns collection to load into
Determines if a column is read-only based on the field properties.Signature:Parameters:
AColumn- The column to check
True if the column’s field is read-only, False otherwise.Sets a cell value, updating the underlying dataset field.Signature:Parameters:
AColumn- The column to updateARow- The row indexAText- The new value as a string
Calculates the optimal column width based on the data and painter.Signature:Parameters:
APainter- The painter used for measuring textAColumn- The column to measure
Called when the grid enters or exits edit mode.Signature:Parameters:
AMode- The edit mode state
Refreshes the grid data from the dataset.Signature:Example:
Complete Examples
Basic Database Grid
Advanced Configuration
Master-Detail Grids
Custom Field Linking
See Also
- TVirtualData - Base class for all data adapters
- TDataSet Binding - Guide to working with datasets
- Database Grid Examples - Complete examples
