Skip to main content

Overview

TDataItem is the main class of TeeBI, representing a column of data that can own sub-columns. It’s similar to a table column but with support for hierarchical structures. TDataItem can store data of various types (integers, floats, text, datetime, boolean) and provides rich functionality for data manipulation, sorting, and statistical analysis.

Constructors

Create()
constructor
Creates a new TDataItem with unknown data kind.
var Data: TDataItem;
Data := TDataItem.Create;
Create(Table: Boolean)
constructor
Creates a new TDataItem, optionally configured as a table.
Table
Boolean
Set to True to create a table-mode data item that can contain sub-items
var Table: TDataItem;
Table := TDataItem.Create(True);
Create(AKind: TDataKind)
constructor
Creates a new TDataItem with a specific data kind.
AKind
TDataKind
The data type for this column (dkInt32, dkText, etc.)
var IntColumn: TDataItem;
IntColumn := TDataItem.Create(dkInt32);
Create(AKind: TDataKind; AName: String)
constructor
Creates a new TDataItem with a specific data kind and name.
AKind
TDataKind
The data type for this column
AName
String
The name of the data column
var AgeColumn: TDataItem;
AgeColumn := TDataItem.Create(dkInt32, 'Age');
Create(AData: TDataArray)
constructor
Creates a new TDataItem containing the specified array of sub-items.
AData
TDataArray
Array of TDataItem objects to add as sub-items
Create(AProvider: TDataProvider)
constructor
Creates a new TDataItem with a data provider for lazy loading.
AProvider
TDataProvider
Provider responsible for loading data just-in-time

Properties

Count
TInteger
required
Returns the number of data values in this item.
ShowMessage('Rows: ' + IntToStr(Data.Count));
Name
String
The name/label of this data item.
Data.Name := 'Sales';
Kind
TDataKind
The data type of this item (read-only). Once set, it should never be changed.Possible values:
  • dkInt32 - 32-bit integer
  • dkInt64 - 64-bit integer
  • dkSingle - Single precision float
  • dkDouble - Double precision float
  • dkExtended - Extended precision float
  • dkText - String/text
  • dkDateTime - Date and time
  • dkBoolean - Boolean
  • dkUnknown - Unknown/unspecified
if Data.Kind = dkInt32 then
  ShowMessage('Integer column');
Parent
TDataItem
The parent TDataItem that owns this data item.
Items
TDataItems
Collection of sub-items (child columns) within this data item.
for I := 0 to Data.Items.Count - 1 do
  ShowMessage(Data.Items[I].Name);
Stats
TDataStats
Statistical information about the data (min, max, mean, variance, etc.).
ShowMessage('Average: ' + FloatToStr(Data.Stats.Mean));
Missing
TMissingData
Manages null/missing values in this data item.
Data.Missing[5] := True; // Mark row 5 as missing
if Data.Missing[10] then
  ShowMessage('Row 10 has missing data');
Provider
TDataProvider
The object responsible for loading this item’s data on-demand.
Master
TDataItem
The master data item in a master-detail relationship.
AsTable
Boolean
True when this data represents a table (containing sub-items as columns).
Primary
Boolean
True when this data is the primary key of its parent.
Unique
Boolean
True when all values are distinct (no duplicates).

Data Arrays

Each TDataItem has typed arrays for storing actual data values:
Int32Data
TInt32Array
Array of 32-bit integers when Kind = dkInt32.
Int64Data
TInt64Array
Array of 64-bit integers when Kind = dkInt64.
SingleData
TSingleArray
Array of single-precision floats when Kind = dkSingle.
DoubleData
TDoubleArray
Array of double-precision floats when Kind = dkDouble.
ExtendedData
TExtendedArray
Array of extended-precision floats when Kind = dkExtended.
TextData
TTextArray
Array of strings when Kind = dkText.
DateTimeData
TDateTimeArray
Array of datetime values when Kind = dkDateTime.
BooleanData
TBooleanArray
Array of boolean values when Kind = dkBoolean.

Methods

Data Manipulation

Resize
procedure
Changes the size of the data arrays.
Size
TInteger
required
The new size for the data arrays
Data.Resize(100); // Resize to hold 100 rows
Append
function
Adds a new row to the data item with the provided values.
Values
Array of Variant
required
Values to append. For table mode, must match column count.
Returns the index of the newly added row.
// For a table with Name, Age, City columns
Table.Append(['John', 25, 'NYC']);

// For a single column
Column.Append([42]);
Insert
procedure
Inserts a new item at the specified position.
AtIndex
TInteger
required
The position where to insert the new item
AMissing
Boolean
default:"True"
Whether to mark the inserted value as missing
Data.Insert(10, False); // Insert at position 10
Delete
procedure
Deletes one or more rows starting at the specified position.
Row
TInteger
required
Starting row index to delete
ACount
TInteger
default:"1"
Number of rows to delete
Data.Delete(5);      // Delete row 5
Data.Delete(10, 3);  // Delete rows 10, 11, 12
Clear
procedure
Removes all data and sub-items from this data item.
Data.Clear;
ClearData
procedure
Removes all data values but keeps the structure.
Recursive
Boolean
default:"False"
If True, also clears data from all sub-items
Data.ClearData(True); // Clear all data recursively

Sorting

SortBy
procedure
Sorts the data by the specified data item column.
AData
TDataItem
required
The column to sort by
Ascending
Boolean
default:"True"
Sort direction (True = ascending, False = descending)
IgnoreTextCase
Boolean
default:"False"
For text columns, whether to ignore case when sorting
Table.SortBy(Table['Name'], True, True); // Sort by Name, case-insensitive

Data Access

DataToString
function
Converts the data value at the specified index to a string.
Index
TInteger
required
The row index to convert
Returns the string representation of the value.
S := Data.DataToString(0); // Get first value as string
Compare
function
Compares two data values at specified positions.
A
TInteger
required
First row index
B
TInteger
required
Second row index
IgnoreTextCase
Boolean
default:"False"
For text data, whether to ignore case
Returns -1 if A < B, 0 if A = B, 1 if A > B.
if Data.Compare(0, 1) < 0 then
  ShowMessage('First value is smaller');
CopyFrom
procedure
Copies a value from a source data item.
DestIndex
TInteger
required
Destination row index in this item
Source
TDataItem
required
Source data item to copy from
SourceIndex
TInteger
required
Source row index to copy
Data.CopyFrom(0, SourceData, 5); // Copy row 5 from source to row 0

Loading and Persistence

Load
procedure
Loads data from the associated Provider.
Children
Boolean
Whether to also load child items
Data.Load(True); // Load this item and all children
LoadFromFile
class function
Loads a TDataItem from a file.
AFileName
String
required
Path to the file to load
Returns the loaded TDataItem.
Data := TDataItem.LoadFromFile('data.bi');
SaveToFile
procedure
Saves this TDataItem to a file.
AFileName
String
required
Path where to save the file
Data.SaveToFile('output.bi');
UnLoadData
procedure
Frees memory by unloading data (can be reloaded later).
InvalidItems
Boolean
default:"False"
Whether to invalidate the items structure
Data.UnLoadData; // Free memory, keep structure

Statistics and Analysis

ReCalculate
procedure
Recalculates all statistics for this item and optionally for all sub-items.
Parallel
Boolean
default:"False"
Whether to use parallel threads for calculation
Data.ReCalculate(True); // Recalculate stats using threads
TotalRows
function
Returns the total number of rows (recursively for hierarchical data).
Total := Data.TotalRows;
TotalColumns
function
Returns the total number of columns (recursively for hierarchical data).
Total := Data.TotalColumns;
FullName
function
Returns the full hierarchical name including parent names.
ShowMessage(Data.FullName); // e.g., "Customers Sales Amount"

Usage Examples

Creating and Populating a Simple Column

var
  Ages: TDataItem;
  I: Integer;
begin
  // Create an integer column
  Ages := TDataItem.Create(dkInt32, 'Age');
  
  // Resize to hold 5 values
  Ages.Resize(5);
  
  // Fill with data
  Ages.Int32Data[0] := 25;
  Ages.Int32Data[1] := 30;
  Ages.Int32Data[2] := 22;
  Ages.Int32Data[3] := 35;
  Ages.Int32Data[4] := 28;
  
  // Access statistics
  ShowMessage('Average age: ' + FloatToStr(Ages.Stats.Mean));
  ShowMessage('Minimum age: ' + IntToStr(TInt32Stats(Ages.Stats).Min));
  
  Ages.Free;
end;

Creating a Table Structure

var
  Customers: TDataItem;
  Name, City: TDataItem;
  Age: TDataItem;
begin
  // Create a table
  Customers := TDataItem.Create(True);
  Customers.Name := 'Customers';
  
  // Add columns
  Name := TDataItem.Create(dkText, 'Name');
  Age := TDataItem.Create(dkInt32, 'Age');
  City := TDataItem.Create(dkText, 'City');
  
  Customers.Items.Add(Name);
  Customers.Items.Add(Age);
  Customers.Items.Add(City);
  
  // Add rows using Append
  Customers.Append(['John Smith', 25, 'New York']);
  Customers.Append(['Jane Doe', 30, 'Boston']);
  Customers.Append(['Bob Wilson', 22, 'Chicago']);
  
  // Sort by name
  Customers.SortBy(Name, True, True);
  
  ShowMessage('Total rows: ' + IntToStr(Customers.Count));
  
  Customers.Free;
end;

Working with Missing Data

var
  Sales: TDataItem;
begin
  Sales := TDataItem.Create(dkDouble, 'Sales');
  Sales.Resize(5);
  
  // Set some values
  Sales.DoubleData[0] := 1000.50;
  Sales.DoubleData[1] := 1500.25;
  Sales.Missing[2] := True;  // Mark row 2 as missing
  Sales.DoubleData[3] := 2000.00;
  Sales.Missing[4] := True;  // Mark row 4 as missing
  
  // Check for missing values
  if Sales.Missing[2] then
    ShowMessage('Row 2 has missing data');
  
  ShowMessage('Missing count: ' + IntToStr(Sales.Missing.MissingCount));
  
  // Statistics automatically handle missing values
  ShowMessage('Average (excluding missing): ' + FloatToStr(Sales.Stats.Mean));
  
  Sales.Free;
end;

Saving and Loading Data

var
  Data, LoadedData: TDataItem;
begin
  // Create and populate data
  Data := TDataItem.Create(dkInt32, 'Numbers');
  Data.Resize(3);
  Data.Int32Data[0] := 10;
  Data.Int32Data[1] := 20;
  Data.Int32Data[2] := 30;
  
  // Save to file
  Data.SaveToFile('numbers.bi');
  Data.Free;
  
  // Load from file
  LoadedData := TDataItem.LoadFromFile('numbers.bi');
  ShowMessage('Loaded ' + IntToStr(LoadedData.Count) + ' values');
  
  LoadedData.Free;
end;

See Also

Build docs developers (and LLMs) love