|
|
Home » U++ Library support » U++ Core » Init a ctrl inside INITBLOCK
|
Re: Init a ctrl inside INITBLOCK [message #35094 is a reply to message #35090] |
Wed, 11 January 2012 10:39 |
|
I think it is because you are using some GUI stuff before it is initialized, like font sizes, styles etc. Safe solution should be to just make the RegisterExample() store the list of things to be initialized into some container. The actual initialization can then by done by separate function called in GUI_APP_MAIN or in the constructor of the application window.
Best regards,
Honza
|
|
|
|
|
|
|
Re: Init a ctrl inside INITBLOCK [message #35111 is a reply to message #35090] |
Thu, 12 January 2012 18:23 |
|
Just for the sake of completeness, here is another solution, based on templates:
template<class T>
inline Ctrl& Create() {
return Single<T>();
};
typedef Ctrl& (*CreateFunc)();
GLOBAL_VAR(Vector<CreateFunc>,sRegisteredObjects);
template<class T>
void Register(){
sRegisteredObjects().Add(Create<T>);
};
GUI_APP_MAIN{
App a;
for(int i=0;i<sRegisteredObjects().GetCount();i++){
Ctrl& c = sRegisteredObjects()[i]();
//do something with it...
}
a.Run();
};
INITBLOCK{
Register<Button>();
Register<EditString>();
};
It is not as simple as yours, but it is less demanding on the registered objects. Also, I'm pretty sure there is many other ways to do this
Honza
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 07:40:43 CET 2024
Total time taken to generate the page: 0.01730 seconds
|
|
|