Board index » delphi » List index out of bounds???

List index out of bounds???

I'm having a little trouble with an application I'm developing in Delphi.  

Whenever a particular code segment executes, Delphi reports "List index out of
bounds".

Here's the code segment it stops at:
     StringList.Strings[0] := inttostr(TabbedNotebook1.PageIndex);

Any help would be greatly appreciated.
Mike
bi...@alpha.dsu.edu

 

Re:List index out of bounds???


In article <bitzm.1514.00899...@columbia.dsu.edu>, bi...@columbia.dsu.edu (Mike Bitz) says:

Quote

>I'm having a little trouble with an application I'm developing in Delphi.  

>Whenever a particular code segment executes, Delphi reports "List index out of
>bounds".

>Here's the code segment it stops at:
>     StringList.Strings[0] := inttostr(TabbedNotebook1.PageIndex);

>Any help would be greatly appreciated.
>Mike
>bi...@alpha.dsu.edu

Has
StringList.Create
been executed.
Have you executed the create but also
StringList.Free

Good luck
Andrew Gunner

Re:List index out of bounds???


On Tue, 23 Jan 1996 12:35:23 UNDEFINED, bi...@columbia.dsu.edu (Mike

Quote
Bitz) wrote:
>I'm having a little trouble with an application I'm developing in Delphi.  

>Whenever a particular code segment executes, Delphi reports "List index out of
>bounds".

>Here's the code segment it stops at:
>     StringList.Strings[0] := inttostr(TabbedNotebook1.PageIndex);

To add a string to the list, call the Add or Insert method. You cannot
refer to an index before anything is added to the list.

--
Ray Lischner         (li...@tempest-sw.com)
Tempest Software, Corvallis, Oregon, USA

Re:List index out of bounds???


MB>I'm having a little trouble with an application I'm developing in Delphi.

MB>Whenever a particular code segment executes, Delphi reports "List index out
MB>bounds".

MB>Here's the code segment it stops at:
MB>     StringList.Strings[0] := inttostr(TabbedNotebook1.PageIndex);

If your list is empty, the above doesn't work. Instead use
StringList.Add(...).

Regards,

Jani

--
---------------------------------------------------------------------
Jani Jarvinen, Helsinki Finland          jani.jrvi...@hiway.fipnet.fi

Check out Help Editor 2.0 for Windows at:
ftp://ftp.mpoli.fi/metropoli/windows/utils/hlped20.zip

1996: Only four years to computer confusion!
What have you done to avoid it?
---------------------------------------------------------------------
---
 * SLMR 2.1a *

Re:List index out of bounds???


Quote
Mike Bitz wrote:
> Whenever a particular code segment executes, Delphi reports "List index out of
> bounds".

> Here's the code segment it stops at:
>      StringList.Strings[0] := inttostr(TabbedNotebook1.PageIndex);

You have insert n:th string before you change it. Check the example below.
(MyList type is TStringList.)

procedure TForm1.InsertClick(Sender: TObject);
begin
  { First insert item to n:th position. However n can't be greater
    than MyList.Count or you'll get List index out of bounds. }
  MyList.Insert(0, IntToStr(Form1.Tag));
end;

procedure TForm1.ChangeClick(Sender: TObject);
begin
  { After you have inserted n:th item you can change it with
    Strings[n] property. }
  MyList.Strings[0] := IntToStr(Form1.Tag);
end;

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Ari Hirviniemi, Lappeenranta, Finland (ari.hirvini...@ktieto.fi)
All my opinions and comments are personal and have nothing to do
with my employer.

Other Threads