Windows (forms) two-step construction #849
Replies: 3 comments 1 reply
-
Most of the wxWidgets classes work that way. The ctor with no parameters simply calls Init() and the ctor with all the parameters calls Init() and then calls Create(). Or put another way: wxDialog dlg(parent, id, title); the above will first call MyDialogBase dlg(parent, id, title); the above will automatically call if (!wxDialog::Create(parent, id, title))
return false; before creating the additional content. So whether you are creating With a Dialog or Panel form, you have two ways to create an instance of the form, the same as you do with the wxWidget class it inherits from. With a Frame form, you only have one way to create an instance. In my mind, it is the Frame which is "stiff" and forces the dev to only have one way to create an instance of the frame. I actually plan at some point to change the Frame form to two-step creation as well since it should be compatible with all existing code unless an inherited class overrides the Create method and doesn't call the base class Create method. All that said, I don't think ever tried this, but I assume given a MyDialog::MyDialog(wxWindow* parent) : MyDialogBase(parent) {} The downside is that you can't do anything before Create is called, whereas MyDialog::MyDialog(wxWindow* parent)
{
// Insert pre-creation initialization code here
Create(parent);
// Insert post-creation initialization code here
} Does all of this make sense or am I overlooking something? |
Beta Was this translation helpful? Give feedback.
-
Thank you, of course it makes sense, except for wxFrame construction which doesn't follow the same principle. |
Beta Was this translation helpful? Give feedback.
-
Pull request #963 adds 2-step construction to wxFrame and the form version of wxPanel. This will be in the 1.1.1 release. |
Beta Was this translation helpful? Give feedback.
-
I've noticed that for wxDialog and wxPanel, the genrated code uses two-step construction only, for wxFrame the genrated code don't use two-step construction.
Talking about windows (forms) constructions, as I see it, two-step construction shouldn't be imposed by the used RAD tool.
In my opinion, windows construction shuld be decided by the developer by using an option for each window (form) used; not a common option for the entire project, but such option shuld be present for each inserted form.
The current way used by wxUIEditor is "stiff" and forces developer to follow its way to generate code, generally speaking should be the opposite.
Beta Was this translation helpful? Give feedback.
All reactions