I have 2 stringgrids. The first grid populates without error, but the second grid keeps giving out of range errors. I populate the grids with titles at runtime, then set both grids to 1 row. I then display any data that the textfiles might have with the call to DisplayData. sg1 populates fine, as shld sg2...but it fails. The increment line is set for sg1, but both grids are using it since both are now set to first row.
sg1 is the first grid
sg2 is the second grid
Error: Index out of range Cell[Col=1 Row=1
I can comment out the sg2 lines one at a time, and the error just moves to the next line and throws an error for that line. I have both grid rows set to 1 before this code executes. Again, sg1 populates fine. The issue is sg2.
procedure TForm1.DisplayData;
var
F: TextFile;
rowIndex: integer=1;
s: ShortString;
procedure FillGrid(aRowIndex: integer);
begin
if aRowIndex>sg1.RowCount-1 then
sg1.RowCount:=aRowIndex+1;
sg1.Cells[1,aRowIndex]:= CustRec.RepeatCust;
sg1.Cells[2,aRowIndex]:= IntToStr(CustRec.CustNum);
sg1.Cells[3,aRowIndex]:= IntToStr(CustRec.OrderNum);
sg1.Cells[4,aRowIndex]:= CustRec.LastName;
sg1.Cells[5,aRowIndex]:= CustRec.FirstName;
sg1.Cells[6,aRowIndex]:= CustRec.Address;
sg1.Cells[7,aRowIndex]:= CustRec.City;
sg1.Cells[8,aRowIndex]:= CustRec.State;
sg1.Cells[9,aRowIndex]:= CustRec.Zip;
sg1.Cells[10,aRowIndex]:= CustRec.Email1;
sg1.Cells[11,aRowIndex]:= CustRec.Email2;
sg1.Cells[12,aRowIndex]:= CustRec.HomeNum;
sg1.Cells[13,aRowIndex]:= CustRec.CellNum;
sg1.Cells[14,aRowIndex]:= CustRec.WorkNum;
sg1.Cells[15,aRowIndex]:= CustRec.Ext;
sg2.Cells[1,aRowIndex]:= IntToStr(CustRec.CustNum);
sg2.Cells[2,aRowIndex]:= IntToStr(CustRec.OrderNum);
sg2.Cells[3,aRowIndex]:= CustRec.I]"]>Blockedrdered;
sg2.Cells[4,aRowIndex]:= IntToStr(CustRec.Quantity);
sg2.Cells[5,aRowIndex]:= IntToStr(CustRec.Cost);
sg2.Cells[6,aRowIndex]:= IntToStr(CustRec.Tax);
sg2.Cells[7,aRowIndex]:= IntToStr(CustRec.TotalCost);
sg2.Cells[8,aRowIndex]:= CustRec.MaterialNeeded;
sg2.Cells[9,aRowIndex]:= CustRec.SpecialNotes;
end;
begin
AssignFile(F, 'gridFile.dat');
try
Reset(F);
while not EOF(F) do begin
readln(F, CustRec.RepeatCust);
readln(F, s);
CustRec.CustNum:=StrToInt(s);
ReadLn(F, s);
CustRec.OrderNum:=StrToInt(s);
readln(F, CustRec.LastName);
readln(F, CustRec.FirstName);
readln(F, CustRec.Address);
readln(F, CustRec.City);
readln(F, CustRec.State);
readln(F, CustRec.Zip);
readln(F, CustRec.Email1);
readln(F, CustRec.Email2);
readln(F, CustRec.HomeNum);
readln(F, CustRec.CellNum);
readln(F, CustRec.WorkNum);
readln(F, CustRec.Ext);
readln(F, CustRec.I]"]>Blockedrdered);
readln(F,s);
CustRec.Quantity:= StrToInt(s);
readln(F,s);
CustRec.Cost:= StrToInt(s);
readln(F,s);
CustRec.Tax:= StrToInt(s);
readln(F,s);
CustRec.TotalCost:= StrToInt(s);
readln(F, CustRec.MaterialNeeded);
readln(F, CustRec.SpecialNotes);
FillGrid(rowIndex);
Inc(rowIndex);
end;
finally
CloseFile(F);
end;
end;
Any insight wld be appreciated.
Landslyde