Assigning a stringlist to a grid's column

I'm trying to assign a TStringList to a TAdvStringGrid.column which works fine till I add an object to the string grid.  Am I doing something wrong? 


function TfrmLookupStringGrid.DoLookup(Columns: TList<TStringList>): integer;
var
  sl: TStringList;
  i : integer;
begin
  Grid.Clear;
  Grid.ColCount := Columns.Count + 1;
  Grid.RowCount := Columns[0].Count + 1;
  i := 1;
  for sl in Columns do
  begin
    Grid.Cols.Assign(sl);
    inc(i);
  end;
  Result := Self.ShowModal;
end;


getting

---------------------------
Debugger Exception Notification
---------------------------
Project GenPort.exe raised exception class EListError with message 'List index out of bounds (-1630371175)'.
---------------------------
Break   Continue   Help   
---------------------------


It works if I explicitly set the object this way


function TfrmLookupStringGrid.DoLookup(Columns: TList<TStringList>): integer;
var
  sl: TStringList;
  Col, Row: integer;
begin
  Grid.Clear;
  Grid.ColCount := Columns.Count + 1;
  Grid.RowCount := Columns[0].Count;
  Col := 1;
  for sl in Columns do
  begin
    if Col = 1 then
    begin
      for Row := 0 to sl.Count - 1 do
      begin
        //Grid.Cols[Col].AddObject(sl[Row], sl.Objects[Row]);  <--- doesn't work
        Grid.Objects[1, Row] := sl.Objects[Row];
        Grid.Cols[Col].Add(sl[Row]);
      end;
    end
    else
        Grid.Cols[Col].Assign(sl);
    inc(Col);
  end;
  Result := Self.ShowModal;
end;

Objects cannot be set via a TStringList, this needs to be done via grid.Objects[col,row]: TObject;

Hi Bruno a question, once an object is set via grid.Objects[col,row]: TObject, I must free the memory when I finished with it? If I use grid.RemoveRows(Row,1); the memory is automatically freed?

Best regards.

Hi,

The grid does not manage the objects. The objects reference is removed, but the object itself is not destroyed, please make sure that you keep an object list or something else with a reference to the object so you can destroy it at application level.