Solved

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

Posted on 2006-11-14
10
447 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filemaker 14 vs Delphi Embarcadero 7 186
Delphi 2010 Export to pdf 2 287
proper way to parse text with delphi 7 101
How to build JSON File in Delphi 6 3 11
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

15 Experts available now in Live!

Get 1:1 Help Now