Inheritance issue: ArgumentError when using wxRuby detach method

39 views Asked by At

I have the following function that is meant to close a panel:

def close_active_panel
  if (@active_panel and @active_panel.class <= Wx::Window)
    @sizer.detach(@active_panel)
    @sizer.remove(0) # 0 is index of first and only item, the active panel
    @active_panel.destroy_children
    @active_panel.destroy
  end
end

This works most of the time, but occasionally (I can't seem to find a pattern with when this happens), it will raise the following exception:

ArgumentError
Wrong arguments for overloaded method 'wxSizer.Detach'. Possible C/C++ prototypes are: bool wxSizer.Detach(wxWindow *window) bool wxSizer.Detach(wxSizer *sizer) bool wxSizer.Detach(size_t index)

It seems strange that this is happening because the only way it should even get to the detach method is if active_panel inherits from the Wx::Window class.

Is there some sort of inheritance trick I am missing here? I have tried outputting the class of the active panel and its parents to ensure it is indeed inheriting from Wx::Window, and the issue persists. Any help would be greatly appreciated.

0

There are 0 answers