Cannot close ContainerControl

I have a nested ContainerControl. I attempt to use the Close method and it just crashes my application. It does not give me any sort of error information to look at. What do I do?

Thanks

[quote=199082:@Oliver Scott-Brown]I have a nested ContainerControl. I attempt to use the Close method and it just crashes my application. It does not give me any sort of error information to look at. What do I do?
[/quote]

Close cannot be used on controls that have not been embedded dynamically. Would it be the case ?

No I believe it has been embedded dynamically. Thanks

I use this Method

Sub removeContainer(w as window, controlname as string)
  for i as Integer = w.ControlCount-1 downto 0
    if w.control(i).Name = "_" + controlname + "." + controlname then
      w.control(i).Close
    end if
  next
End Sub

removeContainer(mainwin, “mycontainername”)

[quote=199088:@Axel Schneider]I use this Method

Sub removeContainer(w as window, controlname as string)
  for i as Integer = w.ControlCount-1 downto 0
    if w.control(i).Name = "_" + controlname + "." + controlname then
      w.control(i).Close
    end if
  next
End Sub

removeContainer(mainwin, “mycontainername”)[/quote]
If I am dynamically adding the controls, how do I work out the names of the controls to remove?

Thankyou very much

If you are dynamically adding controls, you should keep a reference to them in your own array or something. There IS a way to match the pseudo-control placeholder in Control() to an actual object in the global list of all objects, but keeping your own list is easier.

I do have an array of the controls. What do I do with it?

Thanks

Find the control you want to remove, close it, and remove it from the array. I’m not sure I understand the question.

The whole point of the question is that my app crashes returning no error information when I do that.Thanks

Can you reproduce it in a small, fresh project?

I ran into this when I was closing the container from code that was within the container.

Instead of closing the container from within the container, have a Timer on the parent of the container that closes it. When you’re closing the container, instead of embeddedContainer.Close, call “parentWindow.theTimer.Mode = 1” and let it close for you.