StringGrid Out of Bounds

0

I am writing an application that will parse a csv from listview and place it into the stringgrid.  I have keep geting an out of bounds exception and found the issue is that my col is out of bounds.  But I'm not sure why. when the debugger breaks, here are the following variables and values:

Name  Value
sRecord  'Partnumber;Article;Price;Stock'
Row  0
Col  0
PosSemi  11
sField  'Partnumber'

 

.
.
.
procedure TForm1.ParseRecord(sRecord: string; Row: Integer);
var
  Col, RowCount, PosSemi: integer;
  sField: string;
begin
  {we are assuming that all contents inside a column will
   be encapsilated with double-quotes (") if there are any
   spaces, commas, or semi-colons within the columns data}
  sRecord := StringReplace(sRecord, '"', '',
                            [rfReplaceAll]  );  // 1.
  Col := 0;   // first column of the row
  repeat // similar to (do... while statement)
    PosSemi := Pos(';', sRecord);               // 2.
    // if there are semi-colons we will begin to parse each column
    if PosSemi > 0 then
      sField := Copy(sRecord, 1, PosSemi - 1)   // 3.a
    else
      sField := Srecord;                        // 3.b
    SG1.Cells[Col,Row] := sField;              // 4.
    if PosSemi > 0 then
      begin
         Delete(sRecord, 1, PosSemi);
         Col := Col + 1;                           // next column
      end;
  until PosSemi = 0;
end; // Procedure Parse Record
.
.
.

 

 

The Code Breaks at 

.
.
    SG1.Cells[Col,Row] := sField;              // 4.
.
.

 

EArgurmentOutOfRangeException with message 'Column index, 0, out of bounds.  I have tried hard-coding a value for SG1 column and that will throw the same exception.


What am I doing wrong?

Responses (0)
  • There are no replies here yet.
Your Reply

Please login to post a reply