在 VB6 中使用 Printer.Print

发布于 2024-12-27 11:28:33 字数 197 浏览 0 评论 0原文

我有 Java 和 .NET 背景。

在 VB6 中,使用类时似乎并不总是需要创建类的实例。例如,当使用 Printer 类时,您可以简单地说 Printer.print,而不必先创建一个实例,即 Dim Printer As New Printer,然后运行 ​​Printer.Print。我知道Printer是VB6中的系统对象,但为什么不必创建一个实例呢?

I come from a Java and .NET background.

In VB6 it appears that you do not always have to create an instance of a class when using it. For example, when using the Printer class you can simply say Printer.print instead of having to create an instance first i.e. Dim printer As New Printer and then running printer.Print. I know that Printer is a system object in VB6, but why don't you have to create an instance?

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

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

发布评论

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

评论(2

撧情箌佬 2025-01-03 11:28:33

Visual Basic 传统上具有大量可被编译器直接识别的预定义标识符。 Printer 对象就是其中之一。在底层,这是通过 [appobject] 属性 实现的,但这就是小心翼翼地隐藏在语言里。运行时自动创建 COM 组件类的实例,与 As New 语法非常相似。 DAO DBEngine 对象是语言解析器中未预定义的一个示例。

这一切都在 VB.NET 中完成,VB.NET 是一种真正的面向对象语言,具有大型类库,很像 Java。不再有 Printer 对象,您应该使用 PrintDocument 类。旧代码仍支持 Printer 对象,可在 Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6 命名空间中使用。然而,它需要New关键字来创建它的实例。

在 VB6 上投入大量时间和精力要小心,它从各方面来说都是一种严重过时的语言。

Visual Basic traditionally had a large number of pre-defined identifiers that are directly recognized by the compiler. The Printer object is one of those. Under the hood, this is implemented with the [appobject] attribute but that's carefully hidden in the language. The runtime creates an instance of the COM coclass automatically, much like the As New syntax. The DAO DBEngine object would be an example of one that isn't predefined in the language parser.

This is over and done with in VB.NET, a truly object oriented language with a large class library, much like Java. There is no Printer object anymore, you're supposed to use the PrintDocument class. The Printer object is still supported for legacy code, available in the Microsoft.VisualBasic.PowerPacks.Printing.Compatibility.VB6 namespace. It however requires the New keyword to create an instance of it.

Be careful investing a lot of time and energy in VB6, it is in all respects a badly outdated language.

情栀口红 2025-01-03 11:28:33

VB6 并不是一种面向对象的语言,正如您习惯使用较新的语言时所期望的那样。 VB6 将进行隐式实例化,您可以将某些事物视为静态的。例如,您可以声明表单的变量,但不是必须这样做。您可以直接调用表单并对其进行操作,而无需声明它。就打印机而言,它无法显式声明和实例化,但 VB6 已经提供了一个可用的打印机。

VB6 isn't an object oriented language in the same way as you would expect if you are used to newer languages. VB6 will do implicit instantiation and you can treat certain things as if it were static. For example, you can declare a variable of a form, but you don't have to. You can directly call a form and manipulate it without declaring it. In the case of the printer, it can't be explicitly declared and instantiated, but VB6 already has one available.

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