Solved

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

Posted on 2006-11-14
10
455 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

695 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