'nother question… I have a fairly complex piece of script code that controls multiple duplicate sets of identical GUI elements. It does this by having the entire control mechanism in a class, which I can just instantiate multiple times. In total there are 20 sets of controls, each with a dozen callbacks that are called when a GUI element ("button", “textbox”, etc.) has something to report.
To call the callbacks, I could use delegates, but this means that instead of having the full logic of the class internal to the class, I end up with a few hundred delegates - one for each callback in each class instance. This is an unattractive option, as it spreads the class logic all over the place.
Is there a way I can do this without delegates? I.e. can I somehow engineer a callback mechanism that avoids the delegates entirely?
Code example:
class example {
void attach_to_gui (string gui_id) {
@mybutton = button (...find the button based on its gui_id...);
mybutton.setcallback (this, button_callback);
}
void button_callback () {
...
}
button @mybutton;
}
example ex1, ex2, ...ex20;
One possible answer is that I could pass the class name as a string, and just look it up myself in the class object. However, I would appreciate the added type safety I would get from a ‘proper’ solution.