form_loader
Using wvl::form_loader is a way to start a form. For example.
wvl::form_loader<wvl::form>()();
Why have to introduce the form_loader into WVL?
If I want to create a form in a function
void
show_window()
{
wvl::form a;
a.show();
}
In fact, this code is useless to show a form, because the local object a is destructed when the function is returning, and the form is immediately destroyed. Alright, let's change another way to create a form. Take a look at the following code
void
show_window()
{
wvl::form *p = new
form;
p->show();
}
At this time, the form will not be destroyed when the function is returning, but it will bring a new problem that the object refered by p will not be deleted, and this will cause memory leak.
To fix the problem, using wvl::form_loader is a way
void
show_window()
{
wvl::form_loader<wvl::form>()(); //why it has
2-bracket? because it is a functor
}
In fact, wvl::form_loader is also to create an object on the heap, and user will not be involved with the memory management problems in this way, and the form loaded in this way will be deleted automatically when the form is closed by user.
wvl::form_loader can start a form as a module dialog. For example
void
show_window()
{
wvl::form_loader<wvl::form>()(parent_form,
true);
}
Though wvl::form_loader can start a form as a module dialog, creating a module dialog in this way is not agreed. If you want to create a module dialog, you can do it like this
void
show_window()
{
wvl::form a;
a.show_dialog();
}
How can I pass a/some argument(s) to create a form with wvl::form_loader? Think about the following class.
class Form:
public
wvl::form
{
public:
Form(int a, int b):a_(a),
b_(b){};
private:
int
a_;
int b_;
};
There are 2 parameters, if you want to pass 2 arguments for the Form's initilization, hence we have to redesign the Form
struct
argument
{
int
a;
int b;
};
class Form:
public
wvl::form
{
public:
Form(const arguments& arg): a_(arg.a), b_(arg.b){}
private:
int
a_;
int b_;
};
void
show_window()
{
argument arg;
arg.a = 10;
arg.b = 50;
wvl::form_loader<wvl::Form>()(arg,
parent_form);
}