473,513 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to delegate ?

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[i] = new SIMPLEPHONECTRLLib.PhoneClass();
agnphone[i].CallStateChanged += new
SIMPLEPHONECTRLLib._DPhoneEvents_CallStateChangedE ventHandler(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());
}

Nov 16 '05 #1
1 979
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.

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Hugo Mind" <hu******@hotmail.com> wrote in message
news:41********@news.vo.lu...
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[i] = new SIMPLEPHONECTRLLib.PhoneClass();
agnphone[i].CallStateChanged += new
SIMPLEPHONECTRLLib._DPhoneEvents_CallStateChangedE ventHandler(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());
}

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2599
by: Minh Khoa | last post by:
Please give me more information about delegate and its usage? Why do i use it and when?
4
1996
by: ^MisterJingo^ | last post by:
Hi all, I've been trying to get my head around delegates. The book i'm using had a single example, not much explaination, and didn't show how to set up a delegate and pass variables in and out...
3
2308
by: Jeff S | last post by:
Please consider this sample code: It registers a delegate with an event. p1.FirstNameChanged += new Person.NameChanged(p1_FirstNameChanged); Now the following code removes the delegate:...
7
1768
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it...
6
10397
by: David Veeneman | last post by:
I have several events that pass a value in their event args. One event passes an int, another a string, another a DateTime, and so on. Rather than creating a separate set of event args for each...
1
1805
by: Quimbly | last post by:
I'm having some problems comparing delegates. In all sample projects I create, I can't get the problem to occur, but there is definitely a problem with my production code. I can't give all the...
11
2333
by: matsi.inc | last post by:
I am looking to make something like a delegate that i can use in my projects but am having a hard time getting started. The behavior I am most interested in is how a delegate changes it's Invoke...
6
1391
by: damiensawyer | last post by:
Hi, Can someone please explain to me something about delegates? My understanding is as follows. A delegate is basically an object that can hold a reference to a "method" somewhere. That is,...
26
3591
by: raylopez99 | last post by:
Here is a good example that shows generic delegate types. Read this through and you'll have an excellent understanding of how to use these types. You might say that the combination of the generic...
10
2094
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
7265
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7388
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7545
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5095
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4751
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.