The COM Course - Part 1
You wanna know something that's gonna make your day?
Here goes: you're already a COM programmer.
Yup, that's right. I may have never met you, but I'll bet my brother's bottom dollar that you are.
Every time you set the Text property of a Text Box, you're using COM. Every time you run the MoveNext method on the DAO data control, you're using COM. Every time you control Word from within Visual Basic, you're using COM.
So what exactly is COM?
- COM is a method of communication
Imagine a television remote control. You press button one and the television tunes into BBC 1. Or CNN. Or whatever. You press the power button and the television turns itself off. You press a brightness button and suddenly your screen looks like a close-up of the infamous 'White Cat Drinking Milk on a Snowy Day' masterpiece.
Unless you're a television repair geezer which I'm kinda hoping you're not you don't know how this all works. You just press the button and it jumps into action.
That also applies to the world of programming. After all, you don't really know what happens when you change the Text property of your Text Box. Under the covers, it's probably making two-dozen API calls but to the end user, it just displays a certain piece of text in the box.
- COM is a way of reusing code
The good thing about COM is that once you create things that talk the COM-way, that use the COM method of communication, you can use them again and again anywhere.
For example, you could create a COM widget that displays the current date and time. You could then utilise that widget from any program at any time. Your accounts package programmed in Visual Basic could access it. Your order forms in Excel could access it. Your proprietary customer management program written in C++ could access it.
So COM is all about creating 'widgets' that can be reused.
- COM is based around real-life objects
Most widgets created in COM are based around real-life objects. That means after they've been made, they're really easy to use.
Let's imagine you want to add a customer to your computer system. Instead of adding a barrage of data access code, validation algorithms, and weighty database DLLs to your application wouldn't it be easier to run something like Customer.Add?
It sure would. And COM gives you that power.
So COM is a method of communication, a way of reusing code and usually based around real-life objects.
For the rest of this instalment, we'll be taking a lightning tour of COM and Visual Basic. All of our work will be surrounding the creation of a class which could later be turned into a real life COM object all based on a Dog. That's right, a Dog. Makes sense, don't it?
Sure, at times this first instalment might seem a little surreal but it'll teach you the foundations for all future COM coding.
Hey, trust me... I'm a programmer.
Page 2 of 8