473,387 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Delegate question

Alright,

I probably wont be able to get this question answered, but maybe someone has
even more experience than me with delegates... Wow... that sounded
fecisious. =)

So, I'm trying to dynamically create a delegate where the parameters match
on the base level (position is the same, and there base types are the same.)
i.e.

I have an event defined as

Public event myEvent (sender as object, e as MyEventArgs)

now myEventArgs is inherited from System.EventArgs

so I have a method I'm trying to hook to through a delegate... that is
defined as

public sub mySub(sender as object, e as System.EventArgs)

Ok, so signitures don't match, which shouldn't allow a delegate to be
created because it breaks the contract (even though its inherited).

So I try creating a new delegate using System.Delegate.CreateDelegate(Type,
target, method)

so I have this as of right now

delTemp = System.Delegate.CreateDelegate(GetType(System.Even tHandler),
objTarget, methInfo.Name)

evtInfo.AddEventHandler(objHolder, delTemp)

now, this works for creating the delegate, but when I add the hander I get
an error that says "Cannot Bind to Method"

Useless.

So I tried to add in the code

evtInfo.AddEventHandler(objHolder, ctype(delType,
gettype(evtInfo.EventHandlerType)) to convert the delegate to the target
method delegate... No dice...

I get an error on the Ctype... So I'm not sure what to do besides define
events as basic System.Object, System.EventArgs and just pass the data whole
into it.. which may be the best way, but was seeing if anyone else undertood
my plight.

Thanks

CJ


Nov 20 '05 #1
1 2702
I'm the delegate master. Über Delegate Geek.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Chaos, Panic, Disorder, my work here is done"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:vn************@corp.supernews.com...
: Alright,
:
: I probably wont be able to get this question answered, but maybe someone
has
: even more experience than me with delegates... Wow... that sounded
: fecisious. =)
:
: So, I'm trying to dynamically create a delegate where the parameters match
: on the base level (position is the same, and there base types are the
same.)
: i.e.
:
: I have an event defined as
:
: Public event myEvent (sender as object, e as MyEventArgs)
:
: now myEventArgs is inherited from System.EventArgs
:
: so I have a method I'm trying to hook to through a delegate... that is
: defined as
:
: public sub mySub(sender as object, e as System.EventArgs)
:
: Ok, so signitures don't match, which shouldn't allow a delegate to be
: created because it breaks the contract (even though its inherited).
:
: So I try creating a new delegate using
System.Delegate.CreateDelegate(Type,
: target, method)
:
: so I have this as of right now
:
: delTemp = System.Delegate.CreateDelegate(GetType(System.Even tHandler),
: objTarget, methInfo.Name)
:
: evtInfo.AddEventHandler(objHolder, delTemp)
:
:
:
: now, this works for creating the delegate, but when I add the hander I get
: an error that says "Cannot Bind to Method"
:
: Useless.
:
: So I tried to add in the code
:
: evtInfo.AddEventHandler(objHolder, ctype(delType,
: gettype(evtInfo.EventHandlerType)) to convert the delegate to the target
: method delegate... No dice...
:
: I get an error on the Ctype... So I'm not sure what to do besides define
: events as basic System.Object, System.EventArgs and just pass the data
whole
: into it.. which may be the best way, but was seeing if anyone else
undertood
: my plight.
:
:
:
: Thanks
:
: CJ
:
:
:
:
Nov 20 '05 #2

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

Similar topics

2
by: sg71.cherub | last post by:
Here I am meeting a problem. I am transfering unmanaged C/C++ codes to managed C# codes. For the general C/C++ function pointer, it is easy to implement its function by C# delegate. e.g. Declare...
4
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...
1
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...
3
by: Peter Duniho | last post by:
I was reminded in a recent post (http://groups.google.com/group/microsoft.public.dotnet.framework/msg/e649e992db857691?dmode=source) that in C# one can use anonymous delegates without...
4
by: Bob Cramer | last post by:
I don't have a copy of Reflector handy :-( so I'd appreciate if someone could confirm (or clarify) the following. In consideration of the following delegate declaration... delegate string...
2
by: Tony Johansson | last post by:
Hello!! Below is a program copied from a book. The program is easy but there is one thing about the program that I would like to have some more info about. Assume that you have for example 10...
6
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,...
8
by: Advait Mohan Raut | last post by:
Hello, I am using VC# 2005 ; C# 2.0 I am working on the performance measurement tool. For that I need my code to call user defined method along with its parameters. For that should I use a...
3
by: puzzlecracker | last post by:
Sort of new to internal of delegates. My question is when you create a delegate instance, does the surrounding block must be able to see/access method you want delegate to take on. Here is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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,...

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.