C
CJ Taylor
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.EventHandler),
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
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.EventHandler),
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