如何在 VB6 应用程序中重用类?

发布于 2024-07-30 12:27:20 字数 811 浏览 2 评论 0原文

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

alt text

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

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

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

这套数据管理和显示用于多个不同的应用程序。 因此,我编写了几个类来实现逻辑,并在我的应用程序中一次又一次地包含这些类模块。

所以我实际上以“复制和粘贴”模式重用我的课程。 它有效,但有问题。 如果我在一个类中进行更改,我必须在多个应用程序中更改它。

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

简而言之,我想知道如何更优雅地重用它而不仅仅是“复制和粘贴”。 以下是对新的“优雅重用”的一些想法或期望,但不仅限于此。

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

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

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

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

alt text

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.

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.

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.

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) 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) For different applications, the subform in the right may display different information and has different controls and may need extra coding and designing.

(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。"

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

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

发布评论

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

评论(3

甜中书 2024-08-06 12:27:20
  • 创建 ActiveX DLL(非控件)
  • 为表单定义接口
    DLL
  • 将所有逻辑移至 DLL 中的一个或多个类中
    并让例程通过接口与表单交互
  • 在表单中实现接口 应用程序
  • 的一次初始化使表单向 ActiveX DLL 注册自身

这将有效地消除不同应用程序之间的复制和粘贴。

例如,对于我的金属切割应用程序,我有一个形状表单、一个形状屏幕类和一堆形状类。 shape 类的两个方法是 DrawScreen(具有 ShapeScreen 类型的参数)和 GetValues(也具有 ShapeScreen 类型的参数)。

DrawScreen使用ShapeScreen的方法设置入口屏幕,Shape Screen通过IShapeForm接口设置Form。 GetValues 使用 Shape Screen 方法来获取输入的形状值,而形状值又使用 IShapeForm 从表单中获取值。

当我们必须根据客户要求开发不同的形状输入表单时,这种设置被证明是有用的。 新表单仅实现了 IShapeForm 接口,软件的其余部分未受影响。

  • 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.

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 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.

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.

懷念過去 2024-08-06 12:27:20

也许我应该将每个控件封装为一个用户控件,然后制作一个虚拟的ActiveX控件(没有可视界面)将这些控件组织成一个统一的东西。

Maybe I should encapsulate each of the controls to a user control, and then make a virtual ActiveX control (no visual interface) to organize these controls into a united thing.

负佳期 2024-08-06 12:27:20

看起来您拥有的是视图、领域逻辑和数据。 我预见你的主要问题是第二项,它在应用程序之间的外观和逻辑上不是静态的。 也许您需要的是两个独立的控件? 左面板和右面板。 右侧面板可能会实现某种类型的控件数组,因为它们不会是静态的。

It looks like what you have is a view, domain logic, and data. Your major problem I foresee is item two, it is not static in appearance and logic from app to app. Maybe what you need is two separate controls? Left panel and right panel. The right panel probably is going to implement some type array of controls, since they are not going to be static.

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