我正在尝试从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错误] Unit1.pas(179):E2129无法分配给只读属性 in line:StringGrid1.ColumnCount:= Tmp;
任何想法如何解决?
答案 0 :(得分: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));