List index out of bounds (-1)

I updated to AdvStringGrid version 7.9.1.1 and am now getting this error:



   List index out of bounds (-1)



Here is the code (below). I added "sLine" just for debugging and displaying in my try/except statement to figure out what's going on. The big problem for me is that this code executes literally hundreds of times per day on about 150 computers. The "List index out of bounds (-1)" is only thrown about once a day, total (not per machine). So I can't simply duplicate the problem. I have the code send me an email (through a stored procedure) whenever there is an exception. That way, when the users on the manufacturing floor complain, I've already seen the issue and have usually resolved it. But this one has me stumped.



The exception is thrown on the if statement (if sgdCtrlChartMeasurement.AllCells ...). I know this because sLine is never set to the next value (9 or 10).



Code snippet:



for iLoop := iStart downto iEnd do

begin

   sLine := '8 - iLoop=' + IntToStr(iLoop) + ', iStart=' + IntToStr(iStart) + ', iEnd=' + IntToStr(iEnd) + ', RowCount=' + IntToStr(sgdCtrlChartMeasurement.AllRowCount) + ', iCPKHistoryCount=' + IntToStr(iCPKHistoryCount) + ', ctrlchartMSRMNTCOL=' + IntToStr(ctrlchartMSRMNTCOL);



   if sgdCtrlChartMeasurement.AllCells[ctrlchartMSRMNTCOL, iLoop] <> '' then

   begin

      sLine := '9';

      (do stuff)

   end;

   sLine := '10';



In the exception, here is the result of "sLine".



8 - iLoop=249, iStart=249, iEnd=0, RowCount=251, iCPKHistoryCount=250, ctrlchartMSRMNTCOL=0



As you can see, the exception is thrown when asking for the value from:

   sgdCtrlChartMeasurement.AllCells[ctrlchartMSRMNTCOL, iLoop]



which the debug statement shows is:

   sgdCtrlChartMeasurement.AllCells[0, 249]



and the grid has 251 rows (and 11 columns). It has 0 fixed rows, if that matters. It is also interesting that, when this error is thrown, it's ALWAYS on the first iteration through the for loop.



I sure hope someone can shed some light on this. This is not a huge emergency right now, but may become so if it keeps interrupting manufacturing.



Thanks,

Mike

We are not aware of a likely issue that could cause this and there is a lot of details missing from your description to have a better idea about what is going on. I assume you use hidden columns? If so, is the hidden status changing during the runtime of the app? What are the grid's property settings? We'll really need more details to be able to say anything that might make sense.

The last 2 columns are hidden on FormCreate. The hidden column state is never changed. Every time the grid is populated I first unhide all rows and re-hide some of them (the number hidden depends on what data is requested).



Besides a few color changes, the non-default settings are:



ColCount = 11

ColumnSize.Stretch = true

DefaultColWidth = 30

DefaultRowHeight = 25

DrawingStyle = gdsClassic

ScrollBars = ssVertical

ScrollWidth = 16

ShowDesignHelper = false

ShowSelection = false

TapStop = false

That really doesn't help much to reconstruct your situation and be able to reproduce this. I can setup this grid with:


procedure TForm1.FormCreate(Sender: TObject);
begin
  with advstringgrid1 do
  begin
    ColCount := 11;
    ColumnSize.Stretch := true;
    DefaultColWidth := 30;
    DefaultRowHeight := 25;
    DrawingStyle := gdsClassic;
    ScrollBars := ssVertical;
    ScrollWidth := 16;
    ShowDesignHelper := false;
    ShowSelection := false;
    TabStop := false;
  end;

end;

but what's next? How do you fill / hide / manipulate the grid further?

Please, isolate this issue, create a sample source project with which the problem can be reproduced and send it by email, so I can investigate.