後で使用するためにTStringGridからの情報を格納するために、PascalでレコードタイプTTableDataを作成しました。
TTableData = record
header: String[25]; //the header of the column (row 0)
value : String[25]; //the string value of the data
number: Integer; //the y-pos of the data in the table
end;
しかし、TStringGridをトラバースしてセルから値を取得することにより、これらのオブジェクトを初期化しようとすると、値は(''、''、0)になります(いくつかのセルを除いて、どういうわけか問題はありません)。
TStringGridからデータを読み込むための手順は次のとおりです。
procedure TfrmImportData.butDoneClick(Sender: TObject);
begin
Halt;
end;
{ initialize records which are responsible
for storing all information in the table itself }
procedure TfrmImportData.initTableDataObjects();
var
i, j: Integer;
begin
SetLength(tableData, StringGrid1.ColCount, StringGrid1.RowCount);
for j:= 0 to StringGrid1.RowCount-1 do begin
for i:= 0 to StringGrid1.ColCount-1 do begin
with tableData[i,j] do begin
header := StringGrid1.Cells[i,0];
value := StringGrid1.Cells[i,j];
number := i;
end;
end;
end;
for i:= 0 to StringGrid1.RowCount - 1 do begin
for j:=0 to StringGrid1.ColCount - 1 do begin
ShowMessage(tableData[i,j].header+': '+tableData[i,j].value);
end;
end;
end;
ここで何が起こっているのかよくわかりません。ブレークポイントを使用してコードをゆっくりとトラバースすると、データが最初に正しく読み込まれていることがわかります(2番目のforループからtableData [i、j]の上にマウスを置くと、現在の値が表示されます)。ループ自体でShowMessage(...)を実行しようとすると、値が間違って表示されます。
前もって感謝します、