本文介绍了用户定义类型 (UDT) 作为类模块 (VB6) 中 public Sub 中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试解决此问题,但找不到任何解决方案.我在普通模块中定义了一个 UDT,并希望将其用作类模块中 Public Sub 中的参数.然后我得到一个编译错误:

I've tried to solve this problem, but can't find any solution. I have a UDT defined in a normal module, and wanted to use it as parameter in a Public Sub in a Class Module. I then get a compile error:

只有在公共对象模块中定义的公共用户定义类型才能用作类模块公共过程的参数或返回类型或公共用户定义类型的字段

然后我尝试在类中移动我的 UDT,声明为 Private.我收到此编译错误:

I then try to move my UDT in the class, declared as Private. I get this compile error:

私有枚举和用户定义类型不能用作公共过程、公共数据成员或公共用户定义类型的字段的参数或返回类型.

我最终尝试在类中将其声明为 Public,并得到此编译错误:

I finaly try to declare it as Public in the class, and get this compile error:

无法在私有对象模块中定义公共用户定义类型.

那么有没有办法让公共 UDT 用作类中公共子项中的参数?

So is there any way to have a public UDT used as a parameter in a public sub in a class?

推荐答案

总之,没有.仅使用经典 VB 代码最接近的方法是创建一个复制 UDT 的类并使用它.那里肯定有优势,但是如果您还需要将其传递给 API,那么您就很受不了了.

In a word, no. The closest you can come with just Classic VB code would be to create a class that replicates the UDT and use that instead. There are definitely advantages there, but you're hosed if you need to pass that to, say, an API as well.

另一种选择是在类型库中定义 UDT.如果这样做,它可以用作公共方法的参数.

Another option is to define the UDT in a typelib. If you do that, it can be used as a parameter for a public method.

这篇关于用户定义类型 (UDT) 作为类模块 (VB6) 中 public Sub 中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:06
查看更多