Home » U++ Library support » U++ Core » Init a ctrl inside INITBLOCK
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: Thu May 09 18:04:46 CEST 2024
Total time taken to generate the page: 0.02329 seconds
|