473,395 Members | 1,473 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,395 software developers and data experts.

One last delegate question

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
4 2540
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CJ Taylor | last post by:
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...
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.