Recent

Author Topic: [Solved]TStringGrid EGridException index out of range.  (Read 492 times)

cov

  • Sr. Member
  • ****
  • Posts: 252
[Solved]TStringGrid EGridException index out of range.
« on: September 29, 2025, 10:26:19 am »
I'm probably doing something really, really stupid.

Code: Pascal  [Select][+][-]
  1.   fpaths:=TStringList.Create;
  2.   fpaths.Delimiter:=';';
  3.   fpaths.StrictDelimiter:=True;
  4.   fpaths.DelimitedText:=INI.ReadString('Font paths','paths','');
  5.   StringGrid1.Width:=GroupBox1.Width-16;
  6.   for i:=0 to fpaths.Count-1 do
  7.   begin
  8.     if fpaths.Strings[i]<>'' then
  9.       StringGrid1.InsertRowWithValues(n,[fpaths.Strings[i]]);
  10.   end;                                                            
Can anyone advise me what it is?

I've tried setting the rowCount to 1 and clearing it with TStringGrid.Clear.

« Last Edit: September 29, 2025, 11:42:26 am by cov »

Lutz Mändle

  • Full Member
  • ***
  • Posts: 102
Re: TStringGrid EGridException index out of range.
« Reply #1 on: September 29, 2025, 10:43:39 am »
Where is n from in
Code: Pascal  [Select][+][-]
  1.     StringGrid1.InsertRowWithValues(n,[fpaths.Strings[i]]);
  2.  

I guess, it should be i.

Zvoni

  • Hero Member
  • *****
  • Posts: 3466
Re: TStringGrid EGridException index out of range.
« Reply #2 on: September 29, 2025, 10:54:58 am »
*sigh*
Code: Pascal  [Select][+][-]
  1. for i:=0 to fpaths.Count-1 do  //You are using "i" as iterator
  2.   begin
  3.     if fpaths.Strings[i]<>'' then
  4.       StringGrid1.InsertRowWithValues(n,[fpaths.Strings[i]]);  //You are using "n" as Row-Identifier
  5.   end;          
Spot the mistake

EDIT: Why even in such a convoluted way with that InsertRowWithValues?
Why not read the INI-Stuff into a FileStream, and then use LoadFromCSVStream?
https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tcustomstringgrid.loadfromcsvstream.html
« Last Edit: September 29, 2025, 11:03:42 am by Zvoni »
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

cov

  • Sr. Member
  • ****
  • Posts: 252
Re: TStringGrid EGridException index out of range.
« Reply #3 on: September 29, 2025, 11:41:56 am »
Thanks,

Well spotted.

Yes the 'n' was a legacy item in my code that I hadn't noticed.

The reason that I'm loading from an INI file is that I have multiple items and the Font paths are just one of them.

 

TinyPortal © 2005-2018