How to re-use a TeeGrid

TeeGrid VCL / FMX for Embarcadero RAD Studio, Delphi, C++ Builder and Lazarus Free Pascal.
Post Reply
Hans
Newbie
Newbie
Posts: 3
Joined: Thu Aug 18, 2022 12:00 am

How to re-use a TeeGrid

Post by Hans » Thu Aug 18, 2022 1:49 pm

I have a TeeGrid that displays (string) data which can be updated. The data and the number of columns and rows will be updated.

This is what the function looks like that populates the grid:

Code: Select all

procedure TMainForm.FillGrid;
begin
  if Data = nil then Data := TStringsData.Create;
  // Fill Header
  for i := 0 to FieldCount - 1 do
    begin
      Data.Headers[i + 1] := FieldName(i);
    end;
    r := 0;
    // Fill Cells
    for i := 0 to FieldCount - 1 do
    begin
      Data.Rows := r + 1;
      Data[i + 1 ,r] := FieldAsString(i);
    end;
    inc(r);
    NextRecord;
  end;
  TeeGrid.Data := Data;   
end; 
The Data is declared in the TForm and created in the first run.

The first run everything is fine, however, in a second run, if the number of columns increases, the header shows fine but the cells in the new columns are empty. I have tried calling Data.Free and/or TeeGrid.Columns.Clear and TeeGrid.Rows.Clear, but this doesn't help.

I need a way to reset the Data, how do I do this?

Thanks in advance,
Hans

Hans
Newbie
Newbie
Posts: 3
Joined: Thu Aug 18, 2022 12:00 am

Re: How to re-use a TeeGrid

Post by Hans » Fri Aug 19, 2022 8:17 am

I found the solution myself, you should always call Data := TStringsData.Create; this should not depend on if Data = nil. I thought this would give a memory leak, but this is handled by the Grid properly.

Did I miss this in the documentation?

Post Reply