簡體   English   中英

在FireMonkey Delphi XE2中更改ColumnCount

[英]Changing ColumnCount in FireMonkey Delphi XE2

我正在嘗試在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無法分配給以下行中的只讀屬性:StringGrid1.ColumnCount:= Tmp;

任何想法如何解決它?

從文檔:

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));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM