Visual Basic 2010:如何通过附加对象引用多个对象之一? (类似指针的行为?)

发布于 2024-09-28 23:59:12 字数 489 浏览 0 评论 0原文

我正在使用 Visual Basic 2010 Express 编写一个应用程序。

我有两个来自提供给我的驱动程序 DLL 的类对象。他们有一些我想调用的自己的子例程,并且我想要一种在它们之间切换的简单方法。

我不想编写一大堆这样的代码:

selected = x
...
If selected = x then 
    DriverInstanceX.DoSomething() 
Else If Selected = y then 
    DriverInstanceY.DoSomething()
Endif

我想这样做:

Bob = (some reference to X - NOT a copy of X!)
...
Bob.DoSomething()
Bob.DoSomethingElse()

我确信这真的很容易 - 我只是不知道在哪里看。

感谢您的帮助!

I am writing an application in Visual Basic 2010 Express.

I have two objects of a class from a driver DLL that is provided to me. They have some of their own subroutines that I'd like to call, and I'd like an easy way to toggle between them.

Instead of writing a whole bunch of code like this:

selected = x
...
If selected = x then 
    DriverInstanceX.DoSomething() 
Else If Selected = y then 
    DriverInstanceY.DoSomething()
Endif

I would like to do this:

Bob = (some reference to X - NOT a copy of X!)
...
Bob.DoSomething()
Bob.DoSomethingElse()

I'm sure this is really easy - I am just not sure where to look.

Thanks for any help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白日梦 2024-10-05 23:59:12

' 根据首先选择的内容设置对象,此处...

Dim selectedDriverInstance = new DriverObject

' 现在您可以运行该方法,而无需检查每个选择是否已设置。
selectedDriverInstance.DoSometng()

酷吗?

当然,DriverObject 可以是实例 x 或实例 y,具体取决于您设置的内容,在那里进行赋值并将其设置为我们的固定名称对象 selectedDriverInstance。这样您就可以使用 selectedDriverInstance 执行所有操作,因为它已设置为实例 x 或实例 y,明白吗?

' set the object based on what was selected first, here...

Dim selectedDriverInstance = new DriverObject

' now you can run the method without checking for each as selected was already set.
selectedDriverInstance.DoSometng()

Cool?

Of course, DriverObject can be the instance x or instance y depending on what u set it to, do the assignment there and set it to our fixed name object selectedDriverInstance. this way you can do everything using selectedDriverInstance as it is set to either instance x or instance y already, get me?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文