Skip to main content

Overview

TDataKind is an enumeration that specifies the data type of a TDataItem. Each TDataItem can store one specific type of data, and the Kind property determines which internal array (Int32Data, TextData, etc.) is used.

Enumeration Values

dkInt32
TDataKind
32-bit signed integer (-2,147,483,648 to 2,147,483,647)Used for standard integer values, counts, IDs, and other whole numbers.
Data := TDataItem.Create(dkInt32, 'Quantity');
dkInt64
TDataKind
64-bit signed integer (very large range)Used for large integer values that exceed Int32 range, such as large IDs or financial calculations in cents.
Data := TDataItem.Create(dkInt64, 'TransactionID');
dkSingle
TDataKind
Single-precision floating-point (4 bytes, ~7 decimal digits precision)Used for floating-point values where precision is less critical.
Data := TDataItem.Create(dkSingle, 'Temperature');
dkDouble
TDataKind
Double-precision floating-point (8 bytes, ~15-16 decimal digits precision)The default float type for TeeBI, used for most decimal calculations.
Data := TDataItem.Create(dkDouble, 'Price');
dkExtended
TDataKind
Extended-precision floating-point (10 bytes on x86, same as Double on x64)Used for highest precision calculations on 32-bit platforms.
Data := TDataItem.Create(dkExtended, 'PreciseCalculation');
dkText
TDataKind
String/text dataUsed for text values, names, descriptions, and other string data.
Data := TDataItem.Create(dkText, 'CustomerName');
dkDateTime
TDataKind
Date and time valuesUsed for storing dates, times, or combined datetime values.
Data := TDataItem.Create(dkDateTime, 'OrderDate');
dkBoolean
TDataKind
Boolean (True/False) valuesUsed for flags, yes/no questions, and other binary states.
Data := TDataItem.Create(dkBoolean, 'IsActive');
dkUnknown
TDataKind
Unknown or unspecified data typeDefault value when a TDataItem is created without specifying a kind. Should be set to a specific type before adding data.
Data := TDataItem.Create; // Kind is dkUnknown

Helper Methods

The TDataKindHelper record provides utility methods for working with TDataKind values:
FromString
class function
Converts a string to a TDataKind value.
AText
String
required
The text representation of the data kind (e.g., “Int32”, “Text”)
AKind
TDataKind
Output parameter receiving the parsed TDataKind
Returns True if parsing was successful, False otherwise.
var
  Kind: TDataKind;
begin
  if TDataKind.FromString('Int32', Kind) then
    ShowMessage('Successfully parsed: ' + Kind.ToString);
end;
IsNumeric
function
Returns True if the data kind represents a numeric type.Numeric types include: dkInt32, dkInt64, dkSingle, dkDouble, dkExtended
var
  Kind: TDataKind;
begin
  Kind := dkDouble;
  if Kind.IsNumeric then
    ShowMessage('This is a numeric type');
    
  Kind := dkText;
  if not Kind.IsNumeric then
    ShowMessage('This is not a numeric type');
end;
ToString
function
Converts the TDataKind value to a human-readable string.Returns a string representation of the data kind.
var
  Kind: TDataKind;
begin
  Kind := dkInt32;
  ShowMessage(Kind.ToString); // Shows "Int32"
  
  Kind := dkDateTime;
  ShowMessage(Kind.ToString); // Shows "DateTime"
end;

Usage Examples

Determining Data Type

var
  Data: TDataItem;
begin
  Data := TDataItem.Create(dkDouble, 'Sales');
  
  // Check the data kind
  case Data.Kind of
    dkInt32, dkInt64:
      ShowMessage('Integer data');
    dkSingle, dkDouble, dkExtended:
      ShowMessage('Floating-point data');
    dkText:
      ShowMessage('Text data');
    dkDateTime:
      ShowMessage('Date/Time data');
    dkBoolean:
      ShowMessage('Boolean data');
    dkUnknown:
      ShowMessage('Unknown data type');
  end;
  
  Data.Free;
end;

Using IsNumeric

procedure ProcessData(Data: TDataItem);
begin
  if Data.Kind.IsNumeric then
  begin
    // Calculate statistics for numeric data
    ShowMessage('Mean: ' + FloatToStr(Data.Stats.Mean));
    ShowMessage('Range: ' + FloatToStr(Data.Stats.Range));
  end
  else
  begin
    ShowMessage('Non-numeric data: ' + Data.Kind.ToString);
  end;
end;

Dynamic Type Selection

function CreateColumnFromType(TypeName: String; ColName: String): TDataItem;
var
  Kind: TDataKind;
begin
  if TDataKind.FromString(TypeName, Kind) then
    Result := TDataItem.Create(Kind, ColName)
  else
  begin
    ShowMessage('Unknown type: ' + TypeName + ', using Text');
    Result := TDataItem.Create(dkText, ColName);
  end;
end;

var
  Column: TDataItem;
begin
  // Create columns based on string specifications
  Column := CreateColumnFromType('Int32', 'Age');
  Column.Free;
  
  Column := CreateColumnFromType('Text', 'Name');
  Column.Free;
end;

Type-Safe Data Access

procedure DisplayValue(Data: TDataItem; Index: Integer);
var
  Value: String;
begin
  // Access the appropriate array based on Kind
  case Data.Kind of
    dkInt32:
      Value := IntToStr(Data.Int32Data[Index]);
    dkInt64:
      Value := IntToStr(Data.Int64Data[Index]);
    dkSingle:
      Value := FloatToStr(Data.SingleData[Index]);
    dkDouble:
      Value := FloatToStr(Data.DoubleData[Index]);
    dkExtended:
      Value := FloatToStr(Data.ExtendedData[Index]);
    dkText:
      Value := Data.TextData[Index];
    dkDateTime:
      Value := DateTimeToStr(Data.DateTimeData[Index]);
    dkBoolean:
      Value := BoolToStr(Data.BooleanData[Index], True);
  else
    Value := '(unknown)';
  end;
  
  ShowMessage(Data.Name + '[' + IntToStr(Index) + '] = ' + Value);
end;

Converting Between Types

// Note: TDataItem Kind is read-only and cannot be changed after creation
// To convert, create a new TDataItem with the desired type

function ConvertToText(Source: TDataItem): TDataItem;
var
  I: Integer;
begin
  Result := TDataItem.Create(dkText, Source.Name + '_Text');
  Result.Resize(Source.Count);
  
  for I := 0 to Source.Count - 1 do
  begin
    if Source.Missing[I] then
      Result.Missing[I] := True
    else
      Result.TextData[I] := Source.DataToString(I);
  end;
end;

var
  Numbers: TDataItem;
  Text: TDataItem;
begin
  Numbers := TDataItem.Create(dkInt32, 'Numbers');
  Numbers.Resize(3);
  Numbers.Int32Data[0] := 10;
  Numbers.Int32Data[1] := 20;
  Numbers.Int32Data[2] := 30;
  
  // Convert to text
  Text := ConvertToText(Numbers);
  ShowMessage(Text.TextData[0]); // Shows "10"
  
  Numbers.Free;
  Text.Free;
end;

Performance Considerations

  • Int32: Fastest for integer operations, use when values fit in the range
  • Int64: Slightly slower than Int32, use only when needed for large values
  • Double: Best balance of precision and speed for floating-point
  • Single: Faster but less precise, use for large datasets where precision is less critical
  • Extended: Use only when maximum precision is required on 32-bit platforms
  • String comparisons and sorting are slower than numeric operations
  • Consider using Text statistics sparingly on very large datasets
  • Use IgnoreCase parameter carefully as it affects performance
  • Stored internally as TDateTime (double)
  • Good performance for comparisons and sorting
  • Statistical operations work efficiently
  • Most compact storage (1 byte per value)
  • Very fast comparisons and sorting
  • Ideal for flags and binary states

See Also

  • TDataItem - Main data container class
  • TArrays - Typed array helpers for each data kind

Build docs developers (and LLMs) love