vb.net 对非共享成员的引用需要在调用 public sub 时发生对象引用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13462479/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 16:26:15  来源:igfitidea点击:

Reference to a non-shared member requires an object reference occurs when calling public sub

vb.netpublic-methodobject-reference

提问by Dave Mackey

I have a Public Class "General" in which is a Public Sub "updateDynamics". When I attempt to reference it in the code-behind for a page like so:

我有一个公共类“General”,其中是一个公共子“updateDynamics”。当我尝试在页面的代码隐藏中引用它时:

updateDynamics(get_prospect.dynamicsID)

I get the following error:

我收到以下错误:

reference to a non-shared member requires an object reference

对非共享成员的引用需要对象引用

回答by Tim Schmelter

You either have to make the method Sharedor use an instance of the class General:

您必须创建方法Shared或使用类的实例General

Dim gen = New General()
gen.updateDynamics(get_prospect.dynamicsID)

or

或者

General.updateDynamics(get_prospect.dynamicsID)

Public Shared Sub updateDynamics(dynID As Int32)
    ' ... '
End Sub

Shared(VB.NET)

共享(VB.NET)

回答by Pastor Hampande

Go to the Declaration of the desired object and mark it Shared.

转到所需对象的声明并将其标记为共享。

Friend Shared WithEvents MyGridCustomer As Janus.Windows.GridEX.GridEX

朋友与事件共享 MyGridCustomer 作为 Janus.Windows.GridEX.GridEX