TeeGrid can automatically bind to generic arrays and lists using runtime type information (RTTI). The TVirtualData<T> class introspects your records and classes to generate columns automatically.
TeeGrid supports TArray<T>, TList<T>, TObjectList<T>, and even single record/object instances.
type TCar = class public Brand: String; Wheels: Word; Speed: Double; end;var MyCars: TArray<TCar>; t: Integer;begin SetLength(MyCars, 10); // Create instances for t := 0 to High(MyCars) do MyCars[t] := TCar.Create; // Bind to grid TeeGrid1.Data := TVirtualData<TArray<TCar>>.Create(MyCars); // Cleanup (important!) for t := Low(MyCars) to High(MyCars) do MyCars[t].Free;end;
Memory Management: When using arrays of classes, you’re responsible for creating and freeing object instances. TeeGrid does not own the objects.
var MyIntegers: TArray<Integer>; MyFloats: TArray<Single>; MyStrings: TArray<String>; t: Integer;begin // Array of Integer SetLength(MyIntegers, 100); for t := 0 to High(MyIntegers) do MyIntegers[t] := Random(1000); TeeGrid1.Data := TVirtualArrayData<Integer>.Create(MyIntegers); // Array of Single SetLength(MyFloats, 200); for t := 0 to High(MyFloats) do MyFloats[t] := Random(1000) * 0.01; TeeGrid1.Data := TVirtualData<TArray<Single>>.Create(MyFloats); // Array of String SetLength(MyStrings, 10); for t := 0 to High(MyStrings) do MyStrings[t] := 'Item ' + IntToStr(t); TeeGrid1.Data := TVirtualData<TArray<String>>.Create(MyStrings);end;
var MyPerson: TPerson;begin MyPerson.Name := 'John'; MyPerson.Children := 2; MyPerson.Height := 1.75; // Grid shows one row with all fields as columns TeeGrid1.Data := TVirtualData<TPerson>.Create(MyPerson);end;
Control which fields and properties appear as columns:
const PublicAndPublished = [TMemberVisibility.mvPublic, TMemberVisibility.mvPublished];var MyPersons: TList<TPerson>;begin MyPersons := TList<TPerson>.Create; // Only show public and published members TeeGrid1.Data := TVirtualListData<TPerson>.Create( MyPersons, PublicAndPublished, TRttiMembers.Both, // Fields and Properties False // Don't include ancestor members );end;
var Matrix: TArray<TArray<Integer>>; Row, Col: Integer;begin SetLength(Matrix, 10); // 10 rows for Row := 0 to High(Matrix) do begin SetLength(Matrix[Row], 5); // 5 columns per row for Col := 0 to High(Matrix[Row]) do Matrix[Row][Col] := Row * Col; end; TeeGrid1.Data := TVirtualArray2DData<Integer>.Create(Matrix);end;
TeeGrid uses virtual scrolling (only visible rows are rendered)
Memory usage scales with array size, not visible rows
Consider pagination for very large datasets
Column Width Calculation
Speed up initial display:
// Disable automatic width calculationTeeGrid1.Columns.AutoWidth := False;// Set default width for all columnsTeeGrid1.Columns.DefaultWidth := 100;
Row Height
Optimize row height for better scrolling:
// Fixed height for all rows (fastest)TeeGrid1.Rows.Height.Value := 24;// Automatic height per row (slower, for multi-line text)TeeGrid1.Rows.Height.Automatic := True;