0
votes

I'm trying to load stringgrid from file, in Delphi XE2 Firemonkey. When I doing it in Delphi it looks like that:

procedure TForm1.File2StringGrid(Sender: TObject);
var
F: TextFile;
 Tmp, x, y: Integer;
TmpStr: string;
begin
AssignFile(F, (ExtractFilePath(ParamStr(0))+'stringgrid1.sgf'));
Reset(F);
Readln(F, Tmp);
StringGrid1.ColumnCount:=Tmp;

Readln(F, Tmp);
StringGrid1.RowCount:=Tmp;
for x:=0 to StringGrid1.ColumnCount-1 do
for y:=0 to StringGrid1.RowCount-1 do
begin
  Readln(F, TmpStr);
  StringGrid1.Cells[x,y]:=TmpStr;
 end;
CloseFile(F);
end;

In Firemonkey it's make an error: [DCC Error] Unit1.pas(179): E2129 Cannot assign to a read-only property in line: StringGrid1.ColumnCount:=Tmp;

Any ideas how to fix it??

1

1 Answers

3
votes

From the docs:

property ColumnCount: Integer read GetColumnCount;
...
Set ColumnCount to add or delete columns at the right side of the grid.

So, the docs don't match the source.

Try the following instead:

while StringGrid1.ColumnCount < Tmp do
  StringGrid1.AddObject(TStringColumn.Create(StringGrid1));