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

One last delegate question

P: n/a
What does this mean?

This method creates delegates for static methods only. An instance method is
a method that is associated with an instance of a class; a static method is
a method that is associated with the class itself.

So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) :
Delegate and having some issues...

I have the following code

evtInfo = objHolder.GetType().GetEvent(eRow.EvtName)

methInfo = objTarget.GetType().GetMethod(eRow.TargetDelegate)

delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType, methInfo)

evtInfo.AddEventHandler(objHolder, delTemp)

and have no idea what I'm doing wrong. I keep getting that there is an
ArgumentException where methinfo needs to be a static method... And there is
not a bit of documentation on this.

Now, if I understand this correctly, and understand the word "static" I
understand that to be Shared in VB.NET, would that be the correct
assumption? Or am I just completly wrong in this matter.

I've been reading a lot on this, and I want to be able to release a
framework for Windows Forms for others to use, but can't get past these
little issues. That and if you ever have a complex quesiotn I can answer
it. =)

Hopefully someone is more familar with this than I am.

Thanks again,

CJ
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hey CJ,

: Now, if I understand this correctly, and understand the word "static" I
: understand that to be Shared in VB.NET, would that be the correct
: assumption? Or am I just completly wrong in this matter.

Yes you are correct. Basically, you can't create the delegate using that
overload because the method is not declared as shared.

Try changing this...
: delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
methInfo)

to this:
delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
objTarget, eRow.TargetDelegate)

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

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:OJ*************@tk2msftngp13.phx.gbl...
: What does this mean?
:
: This method creates delegates for static methods only. An instance method
is
: a method that is associated with an instance of a class; a static method
is
: a method that is associated with the class itself.
:
:
:
: So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) :
: Delegate and having some issues...
:
:
:
: I have the following code
:
: evtInfo = objHolder.GetType().GetEvent(eRow.EvtName)
:
: methInfo = objTarget.GetType().GetMethod(eRow.TargetDelegate)
:
: delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
methInfo)
:
: evtInfo.AddEventHandler(objHolder, delTemp)
:
:
:
: and have no idea what I'm doing wrong. I keep getting that there is an
: ArgumentException where methinfo needs to be a static method... And there
is
: not a bit of documentation on this.
:
: Now, if I understand this correctly, and understand the word "static" I
: understand that to be Shared in VB.NET, would that be the correct
: assumption? Or am I just completly wrong in this matter.
:
: I've been reading a lot on this, and I want to be able to release a
: framework for Windows Forms for others to use, but can't get past these
: little issues. That and if you ever have a complex quesiotn I can answer
: it. =)
:
: Hopefully someone is more familar with this than I am.
:
:
:
: Thanks again,
:
: CJ
:
:
Nov 20 '05 #2

P: n/a
Alright, so yeah, it is referring a Static Method as a shared method.

But why does this seem wrong? I'm trying to link an event in one DLL to the
Method in another DLL (excuse me, assemblies). But only this will happen if
both DLL's have an instance created. Which is why I don't understand why I
have to use a static method, but maybe this is just my own stupidity.

What if someone is developing a module for this framework, and doesn't have
a static method though? Or needs to use instance variables within a class.
I don't see how a shared method will be able to access instance methods
(cause they can't unless an instance is created and that just gets tricky)

Do I have to set something in a binding flag? Like CreateInstance in order
to tell it to not go for a static method? Would that be correct in
assuming?

I understand if no one knows the answer to this, but I thought I would
through it out.

I'll keep you all posted as I figure it out.

-CJ
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:OJ*************@tk2msftngp13.phx.gbl...
What does this mean?

This method creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself.

So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) :
Delegate and having some issues...

I have the following code

evtInfo = objHolder.GetType().GetEvent(eRow.EvtName)

methInfo = objTarget.GetType().GetMethod(eRow.TargetDelegate)

delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType, methInfo)
evtInfo.AddEventHandler(objHolder, delTemp)

and have no idea what I'm doing wrong. I keep getting that there is an
ArgumentException where methinfo needs to be a static method... And there is not a bit of documentation on this.

Now, if I understand this correctly, and understand the word "static" I
understand that to be Shared in VB.NET, would that be the correct
assumption? Or am I just completly wrong in this matter.

I've been reading a lot on this, and I want to be able to release a
framework for Windows Forms for others to use, but can't get past these
little issues. That and if you ever have a complex quesiotn I can answer
it. =)

Hopefully someone is more familar with this than I am.

Thanks again,

CJ

Nov 20 '05 #3

P: n/a

"Tom Spink" <th**********@ntlworld.com> wrote in message
news:es**************@TK2MSFTNGP11.phx.gbl...
Hey CJ,

: Now, if I understand this correctly, and understand the word "static" I
: understand that to be Shared in VB.NET, would that be the correct
: assumption? Or am I just completly wrong in this matter.

Yes you are correct. Basically, you can't create the delegate using that
overload because the method is not declared as shared.

Try changing this...
: delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
methInfo)

to this:
delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
objTarget, eRow.TargetDelegate)

Yeah this did it, I could declare the object as non static and it was fine.
Once again, some documentation other than "Target: The Target Event." would
be appreciated for those of us NOT on the .NET development team. =)
Thanks again Tom
--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:OJ*************@tk2msftngp13.phx.gbl...
: What does this mean?
:
: This method creates delegates for static methods only. An instance method is
: a method that is associated with an instance of a class; a static method
is
: a method that is associated with the class itself.
:
:
:
: So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) :
: Delegate and having some issues...
:
:
:
: I have the following code
:
: evtInfo = objHolder.GetType().GetEvent(eRow.EvtName)
:
: methInfo = objTarget.GetType().GetMethod(eRow.TargetDelegate)
:
: delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
methInfo)
:
: evtInfo.AddEventHandler(objHolder, delTemp)
:
:
:
: and have no idea what I'm doing wrong. I keep getting that there is an
: ArgumentException where methinfo needs to be a static method... And there is
: not a bit of documentation on this.
:
: Now, if I understand this correctly, and understand the word "static" I
: understand that to be Shared in VB.NET, would that be the correct
: assumption? Or am I just completly wrong in this matter.
:
: I've been reading a lot on this, and I want to be able to release a
: framework for Windows Forms for others to use, but can't get past these
: little issues. That and if you ever have a complex quesiotn I can answer : it. =)
:
: Hopefully someone is more familar with this than I am.
:
:
:
: Thanks again,
:
: CJ
:
:

Nov 20 '05 #4

P: n/a
You need to create an instance of the object to use an instance method,
because the instance method could rely on instance data...

Public Class Class1
Private m_Var1

Public Sub NotStatic()
MsgBox(m_Var1)
End Sub
End Class

That non-static sub relies of m_Var1, so you need an instance of Class1 to
use it.

Declaring the method as Shared will not allow you to use instance
variables/methods/properties/etc, but an instance of the class will not need
to be created in order for you to use the method.

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

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"CJ Taylor" <no****@blowgoats.com> wrote in message
news:uN*************@TK2MSFTNGP12.phx.gbl...
: Alright, so yeah, it is referring a Static Method as a shared method.
:
: But why does this seem wrong? I'm trying to link an event in one DLL to
the
: Method in another DLL (excuse me, assemblies). But only this will happen
if
: both DLL's have an instance created. Which is why I don't understand why
I
: have to use a static method, but maybe this is just my own stupidity.
:
: What if someone is developing a module for this framework, and doesn't
have
: a static method though? Or needs to use instance variables within a
class.
: I don't see how a shared method will be able to access instance methods
: (cause they can't unless an instance is created and that just gets tricky)
:
: Do I have to set something in a binding flag? Like CreateInstance in
order
: to tell it to not go for a static method? Would that be correct in
: assuming?
:
: I understand if no one knows the answer to this, but I thought I would
: through it out.
:
: I'll keep you all posted as I figure it out.
:
:
:
: -CJ
: "CJ Taylor" <no****@blowgoats.com> wrote in message
: news:OJ*************@tk2msftngp13.phx.gbl...
: > What does this mean?
: >
: > This method creates delegates for static methods only. An instance
method
: is
: > a method that is associated with an instance of a class; a static method
: is
: > a method that is associated with the class itself.
: >
: >
: >
: > So I'm trynig to use System.Delegate.CreateDelegate (Type, MethodInfo) :
: > Delegate and having some issues...
: >
: >
: >
: > I have the following code
: >
: > evtInfo = objHolder.GetType().GetEvent(eRow.EvtName)
: >
: > methInfo = objTarget.GetType().GetMethod(eRow.TargetDelegate)
: >
: > delTemp = System.Delegate.CreateDelegate(evtInfo.EventHandle rType,
: methInfo)
: >
: > evtInfo.AddEventHandler(objHolder, delTemp)
: >
: >
: >
: > and have no idea what I'm doing wrong. I keep getting that there is an
: > ArgumentException where methinfo needs to be a static method... And
there
: is
: > not a bit of documentation on this.
: >
: > Now, if I understand this correctly, and understand the word "static" I
: > understand that to be Shared in VB.NET, would that be the correct
: > assumption? Or am I just completly wrong in this matter.
: >
: > I've been reading a lot on this, and I want to be able to release a
: > framework for Windows Forms for others to use, but can't get past these
: > little issues. That and if you ever have a complex quesiotn I can
answer
: > it. =)
: >
: > Hopefully someone is more familar with this than I am.
: >
: >
: >
: > Thanks again,
: >
: > CJ
: >
: >
:
:
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.