Possible bug report for TStringGrid lazarus / 31-LCL ---------------------------------------------------------------------- MISV · 2014-09-03 11:36 Here is relevant definitions from source: Code: [Select]TVirtualGrid property ColCount: Integer read FColCount write SetColCount; property Celda[Col,Row: Integer]: PCellProps read GetCells write SetCells; function TVirtualGrid.GetCells(Col, Row: Integer): PCellProps; begin   // todo: Check range   Result:=nil;   if (Col<0) or (Row<0) or (Col>=ColCount) or (Row>=RowCount) then     raise EGridException.CreateFmt(rsIndexOutOfRange, [Col, Row]);   Result:=FCells[Col,Row]; end; TCustomGrid property ColCount: Integer read GetColCount write SetColCount default 5; function TCustomGrid.GetColCount: Integer; begin   Result:=FCols.Count; end; function TCustomStringGrid.GetCells(ACol, ARow: Integer): string; var    C: PCellProps; begin   Result:='';   C:=FGrid.Celda[aCol,aRow];   if C<>nil then Result:=C^ .Text; end; ... The problem is this... Suppose you have code like this for C := 0 to myCustomStringGrid.ColCount -1 do begin   myCustomStringGrid.Cells[C,myRow]); end this will call down toTVirtualGrid.GetCells because of the usage of the *Celda* property ... And that gets its colcount from a different place than the code that used TCustomGrid.ColCount Not sure if by design (although I do not think so) It took me some time to figure out what was happening (I am working on a descendant of TStringGrid) ---------------------------------------------------------------------- MISV · 2014-09-03 20:06 This is actually a problem that is hard to fix without touching grids.pas ... Are other people not encountering this issue? ---------------------------------------------------------------------- Mike.Cornflake · 2014-09-03 20:31 I'm not clear what your actual error is.  What is the problem exactly? ---------------------------------------------------------------------- MISV · 2014-09-04 08:24 That the two colcounts do no match. The one place handing linsertion of data into cells uses one colcount field (code in TVirtualGrid) But code in TStringGrid uses a colcount hat maps to FCols At leas what seems to be happening is this: So while you iterate the columns colcount reported by the stringgrid object et cells... The actual GeCells fails because that code ends calling down to virtualgrid which gets its colcount from a field resulting in EGridException being thrown. (In my test, I was using default values... So TStringGrid reported 5 columns in ColCount, but the code threw up when trying to index 4 (i.e. so is colcount was just 4) Anyhow, I will see if there is a logical explanation why this problem is not more widespread. I guess my usage somehow must be nonstandard, but I can no see how-so ---------------------------------------------------------------------- taazz · 2014-09-04 10:25 show your code it is probably something like not subtracting one from the colcount (difference between zero and one based arrays) ---------------------------------------------------------------------- MISV · 2014-09-04 10:47 on my self righ now. During converting my TStringGrid descendant from Delphi to Lazarus (tricky because I have my own columns suff here which I now renamed) I had made a change in SizeChanged handling that would exit if no parent was assigned... And well, that was the cause.