Solved

Problem I have this error message List Out index of bounds (2)

Posted on 2006-11-14
10
450 Views
Last Modified: 2010-04-05
Problem I have this error message List Out index of bounds (2)

I use this code and when I insert given there is this error with open the tabSheet3

  tabSheet := TTabSheet.Create(PageControl1) ;
  tabSheet.PageControl := PageControl1;
  tabSheet.Caption := 'Disque #'+IntToStr(PageControl1.PageCount);
  PageControl1.ActivePageIndex := tabSheet.TabIndex;
  PageControl1.Refresh;

  ListView := TListView.Create(tabSheet);
  ListView.Name := 'ListView'+IntToStr(PageControl1.PageCount);
  ListView.Parent := tabSheet;
  ListView.Align := alClient;
  ListView.ViewStyle := vsReport;
  ListView.Visible := true;
  ListView.Ctl3D := false;
  ListView.RowSelect := true;
  ListView.ReadOnly := true;
  ListView.MultiSelect := true;
  ListView.BevelInner := bvNone;
  ListView.BevelOuter := bvNone;
  ListView.Columns.Add.Caption := 'Name';
  ListView.Columns.Add.Caption := 'Size';
  ListView.Columns.Add.Caption := 'Type';
  ListView.Columns.Add.Caption := 'Path';
  ListView.Columns[0].Width := 125;
  ListView.Columns[1].Width := 115;
  ListView.Columns[2].Width := 185;
  ListView.Columns[3].Width := 485;
  ListView.Columns[0].Alignment := taLeftJustify;
  ListView.Columns[1].Alignment := taRightJustify;
  ListView.Columns[2].Alignment := taLeftJustify;
  ListView.Columns[3].Alignment := taLeftJustify;
  ListView.GridLines := true;
  ImageListHandle := SHGetFileInfo('C:\',0,FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);
  ImageListHandle := SHGetFileInfo('C:\',0,FileInfo,SizeOf(FileInfo),SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, ImageListHandle);

  StatusBar := TStatusBar.Create(tabSheet);
  StatusBar.Name := 'Statusbar'+IntToStr(PageControl1.PageCount);
  StatusBar.Parent := tabSheet;
  StatusBar.Align := alBottom;
  StatusBar.Visible := true;
  StatusBar.Panels.Add.Width := 125;
  StatusBar.Panels.Add.Width := 125;
  StatusBar.Panels.Add.Width := 200;
  StatusBar.Panels.Items[0].Alignment := taCenter;
  StatusBar.Panels.Items[1].Alignment := taCenter;
  StatusBar.Panels.Items[2].Alignment := taLeftJustify;


Why?
0
Comment
Question by:ProgsX
10 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 17941899
on what line do you get the error?
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17942254
Restructure this first

var
  ListView: TListView;
  ListColumn: TListColumn;
begin
  ListView := TListView.Create( nil);

  with ListView do
  begin
    Name        := 'ListView'+IntToStr(PageControl1.PageCount);
    Parent      := TabSheet;
    Align       := alClient;
    Visible     := true;
    ViewStyle   := vsReport;
    Ctl3D       := false;
    RowSelect   := true;
    ReadOnly    := true;
    MultiSelect := true;
    BevelInner  := bvNone;
    BevelOuter  := bvNone;
    GridLines   := true;

    ListColumn          := ListView.Columns.Add;
    ListColumn.Caption  := 'Name';
    ListColumn.Width    := 125;
    ListColumn.Alignment:= taLeftJustify;

    ListColumn          := ListView.Columns.Add;
    ListColumn.Caption  := 'Size';
    ListColumn.Width    := 115;
    ListColumn.Alignment:= taRightJustify;

    ListColumn          := ListView.Columns.Add;
    ListColumn.Caption  := 'Type';
    ListColumn.Width    := 185;
    ListColumn.Alignment:= taLeftJustify;

    ListColumn          := ListView.Columns.Add;
    ListColumn.Caption  := 'Path';
    ListColumn.Width    := 485;
    ListColumn.Alignment:= taLeftJustify;
  end;
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17942300
Also this

var
  StatusPanel: TStatusPanel;
begin
  StatusBar := TStatusBar.Create( nil);
  with StatusBar do
  begin
    Name    := 'Statusbar'+IntToStr(PageControl1.PageCount);
    Parent  := tabSheet;
    Align   := alBottom;
    Visible := true;

    StatusPanel           := StatusBar.Panels.Add;
    StatusPanel.Width     := 125;
    StatusPanel.Alignment := taCenter;

    StatusPanel           := StatusBar.Panels.Add;
    StatusPanel.Width     := 125;
    StatusPanel.Alignment := taCenter;

    StatusPanel           := StatusBar.Panels.Add;
    StatusPanel.Width     := 200;
    StatusPanel.Alignment := taLeftJustify;
  end;
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 15

Expert Comment

by:mikelittlewood
ID: 17942336
Ok well I took out this code, as Im not sure what you are trying to do here, maybe set up an image list but this seems a very odd way to do it.

  ImageListHandle := SHGetFileInfo('C:\',0,FileInfo, SizeOf(FileInfo), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_SMALL, ImageListHandle);
  ImageListHandle := SHGetFileInfo('C:\',0,FileInfo,SizeOf(FileInfo),SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
  SendMessage(ListView.Handle, LVM_SETIMAGELIST, LVSIL_NORMAL, ImageListHandle);

Then I just ran the other code and it worked fine without any errors.
I made 20 tab sheets and no errors occured.

So Im guessing your problem is with the code I took out.
0
 

Author Comment

by:ProgsX
ID: 17942563
I always have the same problem.
0
 
LVL 28

Expert Comment

by:TName
ID: 17942585
ProgsX, your code works for me too (without images that is).  
The problem must be somewhere else. Is any event handler implemented for PageControl1 (e.g. OnChange?)
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 17943600
I'm guessing because you are doing
Name        := 'ListView'+IntToStr(PageControl1.PageCount);
and
StatusBar.Name := 'Statusbar'+IntToStr(PageControl1.PageCount);

later on, you are trying to access something based on those names.
I suspect you should be using
  +IntToStr(PageControl1.PageCount - 1);
or
  +IntToStr(tabSheet.TabIndex);
0
 

Author Comment

by:ProgsX
ID: 17944139
I found my error it is necessary that I create absolutely a loop

example:

  for i := 0 to PageControl1.ActivePage.ControlCount - 1 do
  begin
    if (PageControl1.ActivePage.Controls[i] is TListView) then
      ListView := TListView(PageControl1.ActivePage.Controls[i]);
    if (PageControl1.ActivePage.Controls[i] is TStatusBar) then
      StatusBar := TStatusBar(PageControl1.ActivePage.Controls[i]);
  end;

example error:

  with PageControl1 do
  begin
    if (ActivePage.Controls[tabSheet.TabIndex] is TListView) then
      ListView := TListView(ActivePage.Controls[tabSheet.TabIndex]);
    if (PageControl1.ActivePage.Controls[i] is TStatusBar) then
      StatusBar := TStatusBar(PageControl1.ActivePage.Controls[i]);
  end;

thank you
0
 

Author Comment

by:ProgsX
ID: 17947916
you says, I' m guessing because you are doing


you guesses what I does, you think what?
0
 

Author Comment

by:ProgsX
ID: 17949500
for destroy a tasheet

exemple:

  for i := 0 to PageControl1.ActivePage.ControlCount - 1 do
  begin
    if (PageControl1.ActivePage.Controls[i] is TTabSheet) then
    begin
      TabSheet := TTabSheet(PageControl1.ActivePage.Controls[i]);
      TabSheet.Destroy;
      PageControl1.ActivePageIndex := i-1;
    end;
  end;
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now