wxNotebook::GetPageCount() Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

wxNotebook::GetPageCount()

Post by sethjackson »

I have a problem with the following code:

Code: Select all

for (size_t i = 0; i <m_pNotebook>GetPageCount(); ++i)
{    
    // some other code.....    

    m_pNotebook->DeletePage(i);
}
all of the pages aren't closed (deleted). :P

What is going on here?
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

once the first one is deleted, the indexes are changed.

instead of doing "for i=0 to n", I would do "for I=n to 0"...
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

benedicte wrote:once the first one is deleted, the indexes are changed.

instead of doing "for i=0 to n", I would do "for I=n to 0"...
Hmm like this?

Code: Select all

for (size_t i = m_pNotebook->GetPageCount(); i >= 0; --i)
It didn't work.....
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (size_t i = count; i >= 0; --i)
//...
so as to be sure the GetPageCount() is not evaluated for each loop.
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

benedicte wrote:

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (size_t i = count; i >= 0; --i)
//...
so as to be sure the GetPageCount() is not evaluated for each loop.


Uhh didn't work either. :(
benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte »

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (int i=count-1; i>0; --i)
// ...
<count> pages means numbered from 0 to <n-1>...
so let's decrement from <n-1> to 0.
and use an integer index to be able to go to -1 and stop the loop.

maybe you should also post the rest of your code. It may contain something important.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax »

you could also use something like:

Code: Select all

while(m_pNotebook->GetPageCount() > 0) {
  m_pNotebook->DeletePage(0);
  //...
}
if that doesn't work either, you should just trace through your code to see what's going wrong.
Avi
Super wx Problem Solver
Super wx Problem Solver
Posts: 398
Joined: Mon Aug 30, 2004 9:27 pm
Location: Tel-Aviv, Israel

Post by Avi »

sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

benedicte wrote:

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (int i=count-1; i>0; --i)
// ...
<count> pages means numbered from 0 to <n-1>...
so let's decrement from <n-1> to 0.
and use an integer index to be able to go to -1 and stop the loop.

maybe you should also post the rest of your code. It may contain something important.
Sorry for the looooong response time. Now it works except it doesn't delete the last page..... :(

All the code inside the loop does is check if I need to do something with the NotebookPage inside the tab, and then delete the page with m_pNotebook->DeletePage(i)...... I have commented everything out except for the m_pNotebook->DeletePage(i), but it does the same thing. :P

I can't use DeleteAllPages for the reason stated above. :)
phlox81
wxWorld Domination!
wxWorld Domination!
Posts: 1387
Joined: Thu Aug 18, 2005 7:49 pm
Location: Germany
Contact:

Post by phlox81 »

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (int i=count-1; i>-1; --i)
The last Page has the index 0.
sethjackson
Super wx Problem Solver
Super wx Problem Solver
Posts: 396
Joined: Wed Oct 05, 2005 1:19 am

Post by sethjackson »

phlox81 wrote:

Code: Select all

size_t count = m_pNotebook->GetPageCount();
for (int i=count-1; i>-1; --i)
The last Page has the index 0.
:roll: Thanks. :)
Post Reply