Solved

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

Posted on 2006-11-14
10
445 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

759 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

20 Experts available now in Live!

Get 1:1 Help Now