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

AddressOf issue, can somebody explain this?

P: n/a
first line fails with "Reference to a non-shared member requires an object
reference."
yet second line works... any reasons?

ctxMenu.MenuItems.Add("Add new pattern...", AddressOf
mtTemplateNode.cmdPatternAdd_Click)
ctxMenu.MenuItems.Add("Add new pattern...", New
System.EventHandler(AddressOf mtTemplateNode.cmdPatternAdd_Click))
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
the new in the second line creates an mtTemplateNode object
one does not exist in the first line

Hope this helps..

"Eric Newton" <er**@cc.ensoft-software.com> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl...
first line fails with "Reference to a non-shared member requires an object
reference."
yet second line works... any reasons?

ctxMenu.MenuItems.Add("Add new pattern...", AddressOf
mtTemplateNode.cmdPatternAdd_Click)
ctxMenu.MenuItems.Add("Add new pattern...", New
System.EventHandler(AddressOf mtTemplateNode.cmdPatternAdd_Click))
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

Nov 20 '05 #2

P: n/a
Eric,
What type of construct is mtTemplateNode?

Is it an object, a class, a form, a structure, a variable, something else?

If mtTemplateNode is the name of a class, you cannot (should not) add an
event at the class level to an instance method. You will get a null
reference exception when the event itself was raised.

Try
Dim node As New mtTemplateNode
ctxMenu.MenuItems.Add("Add new pattern...", AddressOf
node.cmdPatternAdd_Click)
ctxMenu.MenuItems.Add("Add new pattern...", New
System.EventHandler(AddressOf node.cmdPatternAdd_Click))
Notice that I am using an instance of the mtTemplateNode class for the event
handler.

Alternatively put Shared in front of the cmdPatternAdd_Click method.

Hope this helps
Jay

"Eric Newton" <er**@cc.ensoft-software.com> wrote in message
news:eX**************@TK2MSFTNGP11.phx.gbl... first line fails with "Reference to a non-shared member requires an object
reference."
yet second line works... any reasons?

ctxMenu.MenuItems.Add("Add new pattern...", AddressOf
mtTemplateNode.cmdPatternAdd_Click)
ctxMenu.MenuItems.Add("Add new pattern...", New
System.EventHandler(AddressOf mtTemplateNode.cmdPatternAdd_Click))
--
Eric Newton
C#/ASP Application Developer
http://ensoft-software.com/
er**@cc.ensoft-software.com [remove the first "CC."]

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.