TCustomStringGrid.Rows property
Provides indexed access to the list of column values for the specified row number.
Declaration
property Rows[index: Integer]: TStrings read GetRows write SetRows;Description
Rows is an indexed
TStrings property which provides
access to the list with the String values for the columns in the row number
specified in
Index. Calls
MapGetColsRows to retrieve
the
TStrings instance used as the value for the property.
The Rows implementation in Lazarus is different than the one in Delphi. In Lazarus, a new TStrings instance is created and used to retrieve the cell content. The programmer is responsible for freeing the object after use. Failure to do so will result in a memory leak.
Cast the property value to TStringList to use the features introduced in the descendent class. For example:
Avoid a memory leak when updating column content:
// this will cause a memory leak because the returned TStrings is not freed Grid.Rows[1].CommaText := '1,2,3,4,5'; Grid.Rows[2].Text := 'a'+#13#10+'s'+#13#10+'d'+#13#10+'f'+#13#10+'g'; // avoids the memory leak from above Lst := TStringList.Create; Lst.CommaText := '1,2,3,4,5'; Grid.Rows[1] := Lst; Lst.Free; Lst := TStringList.Create; Grids.Text := 'a'+#13#10+'s'+#13#10+'d'+#13#10+'f'+#13#10+'g'; Grid.Rows[2] := Lst; Lst.Free;
Store values from a string grid row to a list box:
procedure TForm1.FillListBox1;
var
StrTempList: TStringList;
begin
StrTempList := TStringList(Grid.Rows[4]);
if StrTempList <> nil then
begin
ListBox1.Items.Assign(StrTempList);
StrTempList.Free;
end;
end;An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
