../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER for

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rho
In need of some credit
In need of some credit
Posts: 4
Joined: Sun May 03, 2020 8:04 am

../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER for

Post by Rho » Sun May 03, 2020 8:46 am

Using wxcrafter.wxcp --

1) In wxcrafter.cpp, wxcrafter.wxcp created:

Code: Select all

    m_textCtrl_ID = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
    //and I added the following:
    m_textCtrl_ID->SetDefaultStyle(wxTextAttr(wxTE_PROCESS_ENTER));
2) In Dialog1.cpp I added the ::wxMessageBox statement to the wxcrafter.wxcp created empty method:

Code: Select all

void Dialog1::OnTextctrl_idTextEnter(wxCommandEvent& event)
{
    ::wxMessageBox(_(m_textCtrl_ID->GetValue()));
}
Using wxWidgets 3.1.3 things compile and build with no error, but as soon as I click the button to activate the dialog box containing the wxTextCtrl control, I get the assert shown in the 'Subject' line. I can enter text into the textbox, but pressing ENTER produces nothing.

If I use wxWidgets 3.0 I don't get the assertion when I activate the dialog box, but ENTER still produces nothing.

I also tried the code below and got the same results as just described:

1) In wxcrafter.cpp, wxcrafter.wxcp created:

Code: Select all

    m_textCtrl_ID = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
2) In Dialog1.cpp I added the text to the wxcrafter.wxcp created empty method:

Code: Select all

void Dialog1::OnTextctrl_idTextEnter(wxCommandEvent& event)
{
    wxTextCtrl dlg;
    dlg.SetDefaultStyle(wxTextAttr(wxTE_PROCESS_ENTER));   
    wxString innerD = dlg.GetValue();
    wxSTD cout << innerD << wxSTD endl;
}
I have Bruce Perens' "...GUI Programming with wxWidgets", but I couldn't find the answer to this problem in the book (page 109 was a close as I could get).

Thanks for your help.
Last edited by catalin on Sun May 03, 2020 9:36 am, edited 1 time in total.
Reason: code tags

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2387
Joined: Sun Jan 03, 2010 5:45 pm

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by PB » Sun May 03, 2020 9:39 am

I will try to be kind and assume that this is not a troll post.
Rho wrote:
Sun May 03, 2020 8:46 am

Code: Select all

void Dialog1::OnTextctrl_idTextEnter(wxCommandEvent& event)
{
    wxTextCtrl dlg;
    dlg.SetDefaultStyle(wxTextAttr(wxTE_PROCESS_ENTER));   
    wxString innerD = dlg.GetValue();
    wxSTD cout << innerD << wxSTD endl;
}
I may not understand what you were actually attempting to do here, but:

1. You cannot create controls on a stack, you must create them dynamically (with new).
2. The control is not actually created with a default constructor, Create() must be used together with a default constructor
3. You cannot create controls without a parent.
4. You probably did not even want to create a control here but use an existing one instead.
5. wxTE_PROCESS_ENTER is a control style, not a wxTextAttr style.
6. You do not want to call a wxTextCtrl dlg, it is very confusing.

You probably need to ask what you are trying to achieve as the code you posted makes no sense at all. I will assume you want to handle <Enter> being pressed while in wxTextCtrl...

FWIW, here is a full simple example of hand-written code using wxTE_PROCESS_ENTER:
viewtopic.php?t=45093#p186730

I am not familiar with wxCrafter but it should allow you to set wxTE_PROCESS_ENTER style flag somewhere in the properties of the text control you added to your form. The generated code should then look like

Code: Select all

 m_textCtrl_ID = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxTE_PROCESS_ENTER);
Then, you should use that control in the event handler to retrieve the value, as shown in the referenced code example, i.e, the event handler should look like

Code: Select all

void Dialog1::OnTextctrl_idTextEnter(wxCommandEvent& event)
{
    wxString innerD = m_textCtrl_ID->GetValue();
    wxSTD cout << innerD << wxSTD endl;
}
assuming the event handler was properly connected with m_textCtrl_ID.

DavidHart
Site Admin
Site Admin
Posts: 3969
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by DavidHart » Sun May 03, 2020 12:55 pm

I am not familiar with wxCrafter but it should allow you to set wxTE_PROCESS_ENTER style flag somewhere in the properties of the text control
wxC-textctrl.png
wxC-textctrl.png (28.17 KiB) Viewed 171 times

Rho
In need of some credit
In need of some credit
Posts: 4
Joined: Sun May 03, 2020 8:04 am

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by Rho » Wed May 06, 2020 9:33 pm

Okay, I fixed it but having not coded in many, many years and never having used wxWidgets before, it took me a while to find the solution. Firstly, if I used sudo update-alternatives --config wx-config and set it to ../gtk2-unicode-3.0 I would not get the error, but the text entry box wouldn't work. If I used ../gtx3-unicode-3.1 I would get the error and the text entry box still would not work.

Once I correlated wxWidgets wxTextCtrl constructor:

Code: Select all

wxTextCtrl::wxTextCtrl 	( wxWindow * parent, wxWindowID id, const wxString&  value = wxEmptyString, const wxPoint&  pos = wxDefaultPosition,
		                           const wxSize& size = wxDefaultSize, long  style = 0, const wxValidator& validator = wxDefaultValidator,
		                           const wxString& name = wxTextCtrlNameStr)
To the default constructor wxcrafter generated for my text entry box produced in the wxcrafter.cpp file that initially looked like this:

Code: Select all

m_textCtrl_ID = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), 0);
AND modifying it by changing the last element to wxTE_PROCESS_ENTER as shown here:

Code: Select all

m_textCtrl_ID = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDLG_UNIT(this, wxSize(-1,-1)), wxTE_PROCESS_ENTER);
I can now run my code under any wx-config version without error and the text entry box behaves as I expect it to. As a newby to this wxWidgets running in the CodeLite IDE I figured I would post my solution (even though it might be obvious to those of you who have been doing this for a while) in case someone else bumps into this. Hopefully it will save you some time.
Last edited by catalin on Wed May 06, 2020 9:47 pm, edited 1 time in total.
Reason: code tags

Rho
In need of some credit
In need of some credit
Posts: 4
Joined: Sun May 03, 2020 8:04 am

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by Rho » Wed May 06, 2020 9:40 pm

Oh, and by the way, thanks to PB for pointing me to this solution. It just took some reading to figure out what you were describing with your example and where to find the proper explanation as to why the solution worked.

DavidHart
Site Admin
Site Admin
Posts: 3969
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by DavidHart » Wed May 06, 2020 10:01 pm

Hi,
and set it to ../gtk2-unicode-3.0 I would not get the error, but the text entry box wouldn't work.
Presumably that helpful assert was added in wx3.1.
AND modifying it by changing the last element to wxTE_PROCESS_ENTER as shown here
Did you try adding wxTE_PROCESS_ENTER in the standard way: ticking its box in wxCrafter (see the diagram above)? Doing so has the distinct advantage that it will survive any future alteration to your GUI, which your current alterations won't.

Regards,

David

Rho
In need of some credit
In need of some credit
Posts: 4
Joined: Sun May 03, 2020 8:04 am

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by Rho » Thu May 07, 2020 1:50 pm

Hello David,

Your recommendation turned out to be the solution I finally implemented. I tried using PB’s recommendation (which worked), but every time a made a change in the wxcrafters.wxcp workspace and generated the latest code, not surprisingly, it overwrote the previous setting by returning it to ‘0’ instead of leaving it at wxTE_PROCESS_ENTER. I finally found the place in wxcrafter.wxcp to make the change that you described and it worked. Thank you.

Approaching 70 years old and confined by ‘stay at home’ guidelines, I built a Ryzen 3900-based machine a couple months ago and I am in the process of converting to Linux Mint after decades of Mac and Windows. Part of this self-imposed exercise to keep my only operational synapse from calcifying during these Covid-19 times we find ourselves in, has been to learn the CodeLite IDE (which is great!) and wxWidgets using wxcrafters.wxcp (which has been challenging).

I found Bruce Perens’ book, “Cross-Platform GUI Programming with Widgets” which I had hoped would answer all of my wxWidgets questions, but alas it does not. The wxcrafter.wxcp GUI tools design environment is not covered in the book which is what I really need.

Do you have any recommendations regarding wxcrafter documentation? I have searched Google and Amazon and have found nothing like a book on the subject. Again, thank you and PB for your help as I proceed on my journey down this rabbit hole.

Best Regards,

Rho

DavidHart
Site Admin
Site Admin
Posts: 3969
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: ../src/common/textcmn.cpp(1213): assert ""HasFlag(0x0400)"" failed in OnDynamicBind(): Must have wxTE_PROCESS_ENTER

Post by DavidHart » Thu May 07, 2020 2:44 pm

I found Bruce Perens’ book, “Cross-Platform GUI Programming with Widgets” which I had hoped would answer all of my wxWidgets questions, but alas it does not.
It's vintage 2006, and unfortunately hasn't aged well. (wxCrafter wasn't started until approx 2012.) Though it provides basic wx information, and not too much disinformation (e.g. wxT(), unicode...) I still recommend looking at the samples that come with the wx source. They have the considerable advantage of being kept reasonably up to date, and usually approach best-practice.
Do you have any recommendations regarding wxcrafter documentation?
As you probably realise, CodeLite and wxCrafter aren't part of wxWidgets. They are third-party programs and have their own website and documentation: Codelite and wxCrafter. There's also a forum with a Search facility, where you can ask about specific issues.

Post Reply