M
Max
When you add an event handler to some object you need to specify the function to call when the event occurs. Suppose there is a
class TesterClosed() which is called whenever the Tester is closed. Code below:
public void TesterClosed(){}
Tester m_tester = new Tester();
m_tester.Close += new Tester.CloseEventHandler(TesterClosed);
Now suppose I want to do this with late binding where I need to work with objects. The parameter TesterClosed in
Tester.CloseEventHandler(....) is of type "void () type". How do I convert this into an object that I can pass to the same function
with late binding? Code below which I'm not sure I'm doing right:
//m_tester.Close += new Tester.CloseEventHandler(TesterClosed);
Type objClassType = Type.GetTypeFromProgID("Tester.CloseEventHandler");
object [] objParameters_Late = new object[1];
objParameters_Late[0] = TesterClosed; /*I get an error here*/
object objTesterEvent_Late = Activator.CreateInstance(objClassType, objParameters_Late);
objParameters_Late = new object[1];
objParameters_Late[0] = objTesterEvent_Late;
m_tester_Late.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, m_tester_Late, objParameters_Late);
class TesterClosed() which is called whenever the Tester is closed. Code below:
public void TesterClosed(){}
Tester m_tester = new Tester();
m_tester.Close += new Tester.CloseEventHandler(TesterClosed);
Now suppose I want to do this with late binding where I need to work with objects. The parameter TesterClosed in
Tester.CloseEventHandler(....) is of type "void () type". How do I convert this into an object that I can pass to the same function
with late binding? Code below which I'm not sure I'm doing right:
//m_tester.Close += new Tester.CloseEventHandler(TesterClosed);
Type objClassType = Type.GetTypeFromProgID("Tester.CloseEventHandler");
object [] objParameters_Late = new object[1];
objParameters_Late[0] = TesterClosed; /*I get an error here*/
object objTesterEvent_Late = Activator.CreateInstance(objClassType, objParameters_Late);
objParameters_Late = new object[1];
objParameters_Late[0] = objTesterEvent_Late;
m_tester_Late.GetType().InvokeMember("Close", BindingFlags.InvokeMethod, null, m_tester_Late, objParameters_Late);