Don't worry, it's fixed now. BALMLayout which was extending BLayout had overridden RemoveView() and was always returning false. Thanks for the help people. Regards, James On Sun, 2008-06-08 at 15:00 +1200, James Kim wrote: > Thanks for that. But I still can't remove children from fParent. So I > tried the same procedure in another class by passing the same fParent. > > It gave me an error in Haiku. When I execute "bt" in debug, the last > call is _CheckLock() after CountChildren(). > > I am suspecting two things at the moment. > 1. fParent is actually not the parent of these 14 child BViews and there > is another BView in between. > 2. fParent is locked or in use at the time. > > I think it would more likely be 2, because in the other class, it > actually counted the number of children to be 14, which is correct. I > could add a child, which would consequently count to 15. But when I > attempted removing a child, it would remain at 15 and RemoveChild would > return false. I am not too sure if 2 is the main cause, but if so, how > do you unlock a BView that is in use? Or any alternative ideas? Thanks. > > > Regards, > > James > > > On Sat, 2008-06-07 at 12:34 +0200, Ingo Weinhold wrote: > > On 2008-06-07 at 12:30:40 [+0200], Axel Dörfler <axeld@xxxxxxxxxxxxxxxx> > > wrote: > > > "Rene Gollent" <anevilyak@xxxxxxxxx> wrote: > > > > while (fParent->CountChildren() > 0) { > > > > fParent->RemoveChild(fParent->ChildAt(0)); > > > > printf("%d\n", fParent->CountChildren()); > > > > } > > > > > > And since BView::CountChildren() is O(n), you should actually do: > > > > > > while (true) { > > > BView* view = fParent->ChildAt(0); > > > if (view == NULL) > > > break; > > > > > > fParent->RemoveChild(view); > > > } > > > > Which can be written more compactly: > > > > while (BView* view = fParent->ChildAt(0)) > > fParent->RemoveChild(view); > > > > CU, Ingo > > > >