0

我正在尝试在 Delphi XE2 Firemonkey 中从文件中加载 stringgrid。当我在 Delphi 中这样做时,它看起来像这样:

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;

在 Firemonkey 中出错:[DCC Error] Unit1.pas(179): E2129 Cannot assign to a read-only property in line: StringGrid1.ColumnCount:=Tmp;

任何想法如何解决它?

4

1 回答 1

3

从文档:

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

因此,文档与来源不匹配。

请尝试以下操作:

while StringGrid1.ColumnCount < Tmp do
  StringGrid1.AddObject(TStringColumn.Create(StringGrid1));
于 2012-12-31T17:04:52.987 回答