By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Delegate question

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.