Page 1 of 1

How to re-use a TeeGrid

Posted: Thu Aug 18, 2022 1:49 pm
by 18694190
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

Re: How to re-use a TeeGrid

Posted: Fri Aug 19, 2022 8:17 am
by 18694190
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?