如何在VB6应用程序中重用类? [英] How can I reuse classes in my VB6 application?

查看:103
本文介绍了如何在VB6应用程序中重用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,由于我正在使用VB6,请将您的建议仅限于适用于VB6的技术。

First of all, as I am using VB6, please confine your kind suggestions to techniques applied to VB6.

我有一组彼此相关的控件,如上图所示。它包括几个树视图,一个拆分栏,一个列表视图,一个子窗体(一个用户控件)等。

I have a set of controls related to each other as the above figure shows. It includes several treeviews, a split bar, a listview, a subform( a usercontrol), and etc.

当我单击或更改左侧的树视图节点时,正确的控件将相应地更改其显示,反之亦然。

When I click or change the treeview nodes in the left, the right controls will change their display accordingly, and vice versa.

幕后数据保存在Access数据库中。

The data behind the scene is maintained in an Access database.

这组数据管理和显示在几种不同的应用程序中使用。所以我写了几个类来实现逻辑,并在我的应用程序中一次又一次地包含这些类模块。

This set of data management and display is used in several different applications. So I wrote several classes to implement the logic and include these classes modules again and again in my applications.

所以我实际上是 REUSE 我的类在复制和粘贴模式下。它有效,但是有问题。如果要在类中进行更改,则必须在几个应用程序中进行更改。

So I am actually REUSE my classes in a "copy and paste" mode. It works but it have problems. If I make a change in a class, I have to change it in several applications.

这些天,我正在考虑将它们变成所谓的ActiveX组件。但是我不确定应该开发哪种ActiveX组件来重用整个体系结构。

These days I am thinking about making them into the so-called ActiveX components. But I am not sure which kind of ActiveX components should I develop to reuse the whole architecture.

简而言之,我想知道如何重用它。 不仅仅是复制并粘贴。下面是对新优美的重用的一些想法或期望,但不仅限于此。

In a nutshell, I want to know how can I reuse it more gracefully than just "copy and paste". Below is some ideas or expectation of the new "graceful REUSE", but not confine to them.

(1)我希望它看起来像一个具有属性的ActiveX控件。页面,以便我可以在设计时设置它的某些属性。

(1) I hope it looks like an ActiveX control which has a property page so that I can set some properties of it during design time.

(2)对于不同的应用程序,右侧的子窗体可能显示不同的信息并具有不同的控件和可能需要额外的编码和设计。

(2) For different applications, the subform in the right may display different information and has different controls and may need extra coding and designing.

(3)另外,我可能需要为不同应用程序的树视图和列表视图编写一些新行为。该要求使整个表单的整个用户控件都不适合。因为MSDN表示对ActiveX控件的引用,绝不应该返回到客户端应用程序。

(3) Also I may need to code some new behaviour for the treeview and listview for different applications. This requirement make a whole usercontrol for the whole form not suitable. because MSDN said "References to ActiveX controls,should never be returned to client applications。"

推荐答案


  • 创建ActiveX DLL(非控件)



  • DLL中定义表单的接口

  • 移动所有逻辑进入DLL
    中的一个或多个类,并使例程通过接口与表单交互

  • 以表单形式实现接口

  • 对该应用程序进行一次初始化后,便会使用ActiveX DLL对其自身进行注册。

    • Create a ActiveX DLL (not control)
    • Define a Interface for the form in
      the DLL
    • Move all your logic into one or more class in the DLL and have the routines interact with the form through the interface
    • Implement the Interface in the form
    • One initialization of the app have the form register itself with the ActiveX DLL
    • 这将有效消除不同应用程序之间的复制和粘贴。

      This will effectively eliminate copy and paste between the different apps.

      例如,对于我的金属切削应用,我有一个Shape Form,一个Shape Screen类和一堆形状类,其中两个方法是DrawScreen

      For example for my metal cutting application I have a Shape Form, a Shape Screen class, and a bunch of shape classes. Two of the methods of the shape class are DrawScreen which has a parameters of type ShapeScreen, and GetValues which also has a parameter of type ShapeScreen.

      DrawScreen使用ShapeScre的方法,它具有ShapeScreen类型的参数,而GetValues也具有ShapeScreen类型的参数。 zh_cn设置输入屏幕,形状屏幕通过IShapeForm界面设置表单。 GetValues使用Shape Screen方法获取输入的形状值,然后使用IShapeForm从表单中获取值。

      DrawScreen uses the method of ShapeScreen to setup the entry screen and Shape Screen setup the Form through the IShapeForm interface. The GetValues uses Shape Screen methods to get the entered shape values which in turns uses the IShapeForm to get the values from the form.

      这种设置在我们必须开发时证明是有用的根据客户要求提供不同的形状输入形式。新表单刚刚实现了IShapeForm界面,其余软件未受影响。

      This setup proved useful when we had to develop different shape entry forms in response to customer requests. The new form just implemented the IShapeForm interface and the rest of the software was untouched.

      这篇关于如何在VB6应用程序中重用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆