how to delegate ?

  • Thread starter Thread starter Hugo Mind
  • Start date Start date
H

Hugo Mind

Does someone knows how I could add an additional parameter to en event.
See the code below : event are fired but I need to know from which object
the event came.

Could someone explain with a code example please ?

Thank you in advance,

Example:

for (int i = 0; i < 10; i++)
{
agnphone = new SIMPLEPHONECTRLLib.PhoneClass();
agnphone.CallStateChanged += new
SIMPLEPHONECTRLLib._DPhoneEvents_CallStateChangedEventHandler(InvadeControl_CallStateChanged);
}

private void InvadeControl_CallStateChanged(int CallHandle, int CallState,
int StateDependantInfo, int Privilege)
{
staticlogger.sLog(5,0, "EVENT :: CallState has changed for handle : " +
CallHandle.ToString());
}
 
Hugo,

Instead of sending in parms, why not create an Arguments class inheriting
from the EventArgs class. That way, you can add more parms without changing
the signatures of the methods that listen to the events.

public class MyEventArgs : EventArgs
{
public int parm1;
public int parm2;
public string parm3;

... etc
}

change your delegate signature to:

public delegate DPhoneEvents_CallStateChangedEventHandler(object sender,
MyEventArgs e);

Let us know if that works for you.
 
Back
Top