Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2004-03

TStringList index

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Taj Morton
Hi all,
This code has been driving me nuts for the past week.
      IDs:=TStringList.Create;
      for i:=0 to Datab.List_Field.Count-1 do
      begin
	 Tmp:=TStringList(Datab.List_Field.items[i]);
	 IDs.Strings[i]:=Tmp.Strings[0];
	 Tmp.Free;
      end;

It crashes with
An unhandled exception occurred at 0x08062FE5 :
ESTRINGLISTERROR : List index exceeds bounds (0)
0x08062FE5

Datab.List_Field.Count-1=18. It appears that IDs is not letting me write to item i. Any ideas?
Thanks, Taj

Vincent Snijders
to Taj Morton
Hi all, This code has been driving me nuts for the past week.

You have to add them to the list, before you can access them.

IDs:=TStringList.Create;

Creates a list without elements

Show quoted text 5 lines
for i:=0 to Datab.List_Field.Count-1 do begin Tmp:=TStringList(Datab.List_Field.items[i]); IDs.Strings[i]:=Tmp.Strings[0];
Instead do:
	 IDs.Add(Tmp.Strings[0]);
Show quoted text 11 lines
Tmp.Free; end; It crashes with An unhandled exception occurred at 0x08062FE5 : ESTRINGLISTERROR : List index exceeds bounds (0) 0x08062FE5 Datab.List_Field.Count-1=18. It appears that IDs is not letting me write to item i. Any ideas? Thanks, Taj

Vincent.

Jesus Reyes
to Taj Morton: This code has been driving me nuts for the past week. IDs:=TStringList.Create; for i:=0…

----- Original Message -----

Earlier message 21 lines
From: Taj Morton To: Sent: Sunday, March 14, 2004 1:04 PM Subject: [fpc-pascal]TStringList index > Hi all, > This code has been driving me nuts for the past week. > IDs:=TStringList.Create; > for i:=0 to Datab.List_Field.Count-1 do > begin > Tmp:=TStringList(Datab.List_Field.items[i]); > IDs.Strings[i]:=Tmp.Strings[0]; > Tmp.Free; > end; IDs.Strings[i] its not allocated, try IDs.Add(Tmp.Strings[0]) instead Regards Jesus Reyes A.