PC Review


Reply
Thread Tools Rate Thread

AddressOf and "me" problem

 
 
mono
Guest
Posts: n/a
 
      15th Aug 2003
Hi,

Target.ParametricMethod(AddressOf Me.MyTest)

doesn't compile, producing the error:
"reference to a non-shared member requires an object reference" whereas

Target.ParametricMethod(AddressOf MyTest)

does compile. In both case that call is made from a non-shared method.
MyTest is not shared. If I make MyTest shared (not workable for me) then
both forms compile.

Target is an instance of a class with these members:

Public Delegate Function KeyTest(ByVal sKey As String) As Boolean

Public Sub ParametricMethod(ByVal oKeyTest As KeyTest)
...
End Sub

and Me is an instance of a class with member:

Public Function MyTest(ByVal oString As String) As Boolean

Isn't Me.MyTest synonymous with MyTest?? Is there something special about
the AddressOf context?

michael


 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      15th Aug 2003
No. This is because VB has very poor syntax because it has inherited all the
crap from VB6.

When you say Me.MyTest - you typically want to call that function. And yes,
when calling the function, you can also just say MyTest

However, with AddressOf - that just expects the name of a function.
Me.MyTest is not a name of a function.

The reason this is confusing is, as I said before, because VB syntax is very
awkward and clumsy.

"mono" <mikeg@n_o_s_p_a_mcimage.com> wrote in message
news:OK$(E-Mail Removed)...
> Hi,
>
> Target.ParametricMethod(AddressOf Me.MyTest)
>
> doesn't compile, producing the error:
> "reference to a non-shared member requires an object reference" whereas
>
> Target.ParametricMethod(AddressOf MyTest)
>
> does compile. In both case that call is made from a non-shared method.
> MyTest is not shared. If I make MyTest shared (not workable for me) then
> both forms compile.
>
> Target is an instance of a class with these members:
>
> Public Delegate Function KeyTest(ByVal sKey As String) As Boolean
>
> Public Sub ParametricMethod(ByVal oKeyTest As KeyTest)
> ...
> End Sub
>
> and Me is an instance of a class with member:
>
> Public Function MyTest(ByVal oString As String) As Boolean
>
> Isn't Me.MyTest synonymous with MyTest?? Is there something special about
> the AddressOf context?
>
> michael
>
>



 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      16th Aug 2003
Michael,

I can't seem to reproduce the behavior you describe. The following
code compiles correctly with all versions of the VB.NET compiler I
tried. Am I missing something?


Option Strict On

Class Foo
Public Delegate Function KeyTest(ByVal sKey As String) As Boolean
Public Sub ParametricMethod(ByVal oKeyTest As KeyTest)
End Sub
End Class

Class Bar
Public Function MyTest(ByVal oString As String) As Boolean
End Function

Sub Test()
Dim Target As New Foo
Target.ParametricMethod(AddressOf Me.MyTest)
End Sub
End Class




Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 25th Feb 2009 11:41 PM
usage "AddressOf TimerProc" in Excel97 tom taol Microsoft Excel Programming 3 14th Jan 2005 09:57 AM
Problem with blank "yes", "no", "cancel" option boxes =?Utf-8?B?Q29saW5HQmxhaW5l?= Windows XP Help 1 3rd Jul 2004 03:35 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 08:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:26 AM.