我可以在 VB6 中使用相同的库作为组件和参考吗?
我想使用 Winsock Comm 控件。某些表单将其用作表单(组件)上的控件,但我也有一些具有引用并创建新的 MSComm 对象的类。
VB6 似乎失败了。您可以将其添加为组件或参考。有没有办法在同一个项目中同时完成这两项工作?
I would like to use the Winsock Comm control. Some forms have used it as a control on the form (component) but I also have some classes which have references and created a new MSComm object.
This seems to fail with VB6. You can either add it as a component or reference. Is there any way to do both in the same project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 mktyplib.exe 编译自定义“直接控件”类型库,如下
所示 在项目中引用 DirectControls10 后,您可以使用 DirectMSComm coclass沿着
MSCommlib.MSComm
用户控件,如下所示...在上面的示例中,
MSComm1
是Form1
上的“通信控件”。您不必必须将此自定义
.tlb
文件分发给您的客户。仅在您的开发机器上使用它。You can use
mktyplib.exe
to compile a custom "direct controls" typelib like thisOnce you reference
DirectControls10
in your project you can useDirectMSComm
coclass alongMSCommlib.MSComm
usercontrol like this... where in the sample above
MSComm1
is a "comm control" onForm1
.You don't have to distribute this custom
.tlb
file to you clients. Use it on your dev machines only.我相信组件引用是一种特殊的引用。因此,一旦引用了某个组件,就可以将其作为引用的库进行访问。
I believe a component reference is a special kind of reference. So once you have referenced a component, you can access it as a referenced library.
您是在谈论 Winsock 还是 MSComm?
如果是后者,请从表单中删除该组件,然后将其作为工具箱中的组件删除。
将其添加为引用,并在以前有组件手动声明实例的表单中;
在
_load
中创建它们,只要变量名称相同,所有事件都应该连接起来。
如果它是 Winsock 组件,那么最简单的方法是使用 OCX 组件和 OCX 组件。根据需要将引用从表单传递到类,因为您无法可靠地提前绑定 Winsock 组件;
set wsck1 = new Winsock
将编译并创建运行良好,但在任何没有安装 VB6 的机器上,它都会失败,因为每次以这种方式创建一个组件时,winsock 组件都会进行许可证验证。我 90% 确信 mscomm 不是这种情况,但无论如何最好进行测试。
Are you talking about Winsock or MSComm?
If its the latter, remove the component from the forms then remove it as a component in the tool box.
Add it as a reference and in the forms where previously there were components declare the instance manually;
creating them in
_load
and all your events should be wired up so long as the variable name is the same.
If its a Winsock component then the simplest way is to use the OCX component & pass a reference from the form to the class as necessary, as you cannot reliably early bind a winsock component;
set wsck1 = new winsock
will compile & run fine but on any machine without VB6 installed it will fail as the winsock component does a license validation everytime one is created in that fashion.I am 90% sure this isnt the case for mscomm but best to test anyway.
无论如何,UserControl 是类的一种特殊形式,因此要包装控件,您需要创建一个 UserControl。您可以通过明确命名的 InvisibleAtRuntime 属性轻松地使非 UI UserControl 在运行时不可见。
A UserControl is a specialized form of Class anyway, so to wrap a control you create a UserControl. You can easily make a non-UI UserControl invisible at runtime via the clearly named InvisibleAtRuntime property.