VB语言

本类阅读TOP10

·Visual Basic 安装程序的制作!!
·VB中使用EXCEL输出
·一个简单的MP3播放器
·VB程序实现WindowsXP效果的界面!!
·VB打造超酷个性化菜单(六)
·透明位图
·平铺与拉伸MDI窗口的背景图 ~!~
·对《VB程序实现WindowsXP效果的界面》一文的补遗
·从Windows资源管理器中拖动文件
·VB打造超酷个性化菜单(一)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
The COM Course - Part 2--By Karl Moore

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

VB-World - ActiveX Development - Articles - The COM Course - Part 2 - Going It Alone
Search VB-World:         
> VBForums.com
> VBSquare.com
> VBAPI.com
  Home  > ActiveX Development > Articles
Email this page
Printer Friendly
More From Karl
Post Feedback

Related
The COM Course - Part 3
The COM Course - Part 2
The COM Course - Part 1
ActiveX Control Tutorial - Part 5
ActiveX Control Tutorial - Part 4

Hot Picks
VB.NET Uncovered: Big Changes
VB.NET Uncovered: Working the Web
Control the Panel
Kill Context
Learn to Program with Visual Basic 6

The COM Course - Part 2

By Karl Moore

Going It Alone

Remember how last week we threw a class into a standard Visual Basic project?

Well, one of the main points in the elegant COM philosophy is that code can be reused.

In other words, if you create an Accounting class in Visual Basic, you shouldn't only be able to access that from your application ?but perhaps also from another VB program your colleague is working on. And maybe an Excel spreadsheet that needs such data. You might even have a C++ programmer that needs to grab certain information for his latest project.

So what do you do? At the moment, you've worked with classes residing inside a standard Visual Basic application. And even if you give them a copy of your final .EXE program, they still won't be able to access the classes or properties within it.

The solution is to throw all the classes into a program of their own. Then they're "COM-enabled".

<Karl: Corr, I just invented that buzzword! COM-enabled. Let me call my trademark people...>

In other words, say your class has an AnnualProfitsToDate property. When this property is retrieved, your class dips into the company database, performs half-a-dozen calculations, then returns a value in pounds. Or dollars. Or Yen. Or green bananas. Or whatever.

Now instead of physically giving the Excel user a chunk of code to access the database, simply give him your 'class program'. This program 'exposes' your class and the AnnualProfitsToDate property, allowing other users to plug into its functionality. And instead of telling the C++ programmer how to manually perform the calculation so he can access the statistic himself, you could also give him this program, saving you both a lot of work.

So let's review this... in addition to throwing classes into Visual Basic projects, you can throw them into programs of their own, called ActiveX components, which say to other programs "Hey, I can do this ?provide an AnnualProfitsToDate property, update the Customers database, etc!".

And all the functionality of your ActiveX program can then be accessed from within any ActiveX-aware programming language. In other words, the AnnualProfitsToDate property can be retrieved from within Excel, C++, Access ?and more!

So how do you create an ActiveX program to hold your classes?

Introduction

Choices, Choices

  In This Article

Introduction - Going It Alone - Choices, Choices - Adding Properties and Methods - Testing your Class - Compiling your Program - Building your Test Program - Testing It All - Conclusion -

ActiveX | Beginning | Controls | Databases | Files | Graphics | Misc | Mouse | Registry
Home | Articles | Code | Projects | Books | Reviews | Discussion Forums
Tech News | Contact Us | Site Map | Join Newsletter | Link To Us
Copyright ©1997-2001 Jelsoft Enterprises Limited. All rights reserved. Privacy Policy.



相关文章

相关软件