Hi all,
I have an object with a delegate method set up. What I want to do is store a method name (in a database say), and then attach the method with that name to the object's delegate.
I have achieved this using reflection - example code is below:
String ProgramName = "TestProgram";
ProgramClass MyObject = new ProgramClass();
MethodInfo ProgramInfo = MyObject.GetType().GetMethod(ProgramName);
Delegate del = Delegate.CreateDelegate(typeof(MyButton.ClickMethod), MyObject, ProgramInfo, false);
MyButton myButton = new MyButton();
myButton.Program = (MyButton.ClickMethod)del;
This does work, though it appears to be a little on the slow side. Essentially, I'm dynamically producing a load of buttons, and each one will have a 'program' attached to it, with is a method that is run when it is clicked - but this method can simply be to write a character (like an on-screen keyboard for example) - so although this method works, I need really a more immediate response.
Does anyone know of a better way to achieve this? Is the using a delegate not the best way?
To summarise - I'm wanting to store a method name in a database, and run that method when a button is pressed.
Any help greatly appreciated.