Author Topic: wxSmith generate wrong Parent  (Read 4931 times)

lastowne

  • Guest
wxSmith generate wrong Parent
« on: March 03, 2021, 03:15:03 am »
Hi,
I'm really new to Code::Blocks and wxSmith.
After a while of trying to add a wxTextCtrl to a wxToolBar with wxSmith i finally managed to add it with "insert new widgets in the current selection" button.
But i'm getting an error :

../../src/common/tbarbase.cpp(230): assert "control->GetParent() == this" failed in InsertControl(): control must have toolbar as parent

The problem is that wxSmith adds the wxTextCtrl with "This" instead of "ToolBar1"

Generated by wxSmith:
Code
    TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    ToolBar1->AddControl(TextCtrl1);

It should be:
Code
    TextCtrl1 = new wxTextCtrl(ToolBar1, ID_TEXTCTRL1, _("Text"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    ToolBar1->AddControl(TextCtrl1);

How to fix it? Or i'm i missing something?

Thanks you!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1644
Re: wxSmith generate wrong Parent
« Reply #1 on: March 03, 2021, 09:36:07 am »
This looks like a bug with far from trivial fix, please create a ticket.

As a workaround you can try putting this in TextCtrl1's "Extra code" field:
Code
TextCtrl1->Reparent(ToolBar1);