Page 1 of 1

wxNotebook::GetPageCount()

Posted: Fri Jun 16, 2006 4:31 pm
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?

Posted: Fri Jun 16, 2006 4:35 pm
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"...

Posted: Fri Jun 16, 2006 4:41 pm
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.....

Posted: Fri Jun 16, 2006 4:43 pm
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.

Posted: Fri Jun 16, 2006 4:49 pm
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. :(

Posted: Fri Jun 16, 2006 5:16 pm
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.

Posted: Fri Jun 16, 2006 5:37 pm
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.

Posted: Fri Jun 16, 2006 6:58 pm
by Avi

Posted: Mon Jun 26, 2006 12:41 pm
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. :)

Posted: Mon Jun 26, 2006 12:48 pm
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.

Posted: Mon Jun 26, 2006 12:56 pm
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. :)