U++ framework
Do not panic. Ask here before giving up.

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 Go to previous messageGo to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1796
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Smile

Honza
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Date& operator++
Next Topic: random functions proposal
Goto Forum:
  


Current Time: Fri Sep 18 09:05:56 GMT+2 2026

Total time taken to generate the page: 0.00715 seconds