I created a TTableData record type in Pascal to store information from TStringGrid for future reference:
TTableData = record
header: String[25];
value : String[25];
number: Integer;
end;
But whenever I try to initialize these objects by going through the TStringGrid and getting the values from the cells, the values become ('', '', 0) (with the exception of a few cells that somehow turn out to be in order).
Here is my procedure for reading in data from 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;
I'm not quite sure what is going on here. When I use breakpoints and walk slowly through the code, I see that the data is initially read correctly (by holding the mouse over tableData [i, j] from the second for loop to see its current value), but when I try ShowMessage (.. .) in the loop itself, the value goes wrong.
Thanks in advance,