Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-14
10
Medium Priority
?
477 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 750 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

Technology Partners: 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

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 I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

604 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