The COM Course - Part 3, Page 5
Before we can test our File component, we need to compile it. But just before we do that, let's take a sneak peek at a few extra options given to us by Visual Basic.
Whilst in your FileCheck code window, take a look at the Properties window.
Here we have the Name, DataBindingBehaviour (for 'binding' the class to a data source) and Persistable (used in controls, allows certain class properties to be saved). You should also have Instancing.
Now after you've set the class name, you probably won't need to worry about the first three. But what about Instancing?
The Instancing property determines whether or not your class can be 'seen' by the application using your ActiveX component and if it can, whether more than one 'instance' should be started at any one time.
Let's take a look at the options, in order of popularity:
- MultiUse This is perhaps the most used option. This uses one 'instance' of your component (one 'process space') to serve all the programs using it. Here, all objects are served by one instance of your component. This saves memory space and can allow you to "share global variables" - but has few other real-life advantages
- Private No-one except other objects in your component can see this class. This is generally used when you need to create a class that will solely be used by the other objects in your class
- GlobalMultiUse Allows you to call the various methods and properties of your class as if they were global functions. In other words, in VB, you don't have to explicitly create a new object, then run that method it's all done automatically. You just call it! Every method or property called runs from one single instance of your component
- PublicNotCreatable This means your class is viewable by all, but only your own classes can create an instance of it. In other words, your end user cannot use the New keyword to create one of these your class must do that and pass it back. This is a little like when you open a recordset in DAO you never create a new recordset, but simply get one back from the OpenRecordset method
- SingleUse This means that every time a new instance of a component is started in code, it fires up another 'instance' of your ActiveX component. In other words, each instance gets its own 'process space'. This does have some limited use, but nothing to worry about. Unsurprisingly, this is the opposite of MultiUse
- GlobalSingleUse As in GlobalMultiUse, except for each object created in code, a new instance of your component is fired up
Now you'll rarely use all of these. Undoubtedly the most popular is MultiUse. Private is sometimes used and GlobalMultiUse can be pretty neat, but the rest are kinda unpopular. Knoooow the feeling. You'll also find most of these options available when creating ActiveX DLLs and they work in just the same way.
Well, my profuse apologies for such a boring interlude, but I'd get a scalding from all the COM whizz-kids if I didn't mention incredulous Instancing.
Anyway, let's fire ahead and compile then test our ActiveX EXE component!
- Click 'File', 'Make File.exe'
- Choose a filename then click OK
Now let's create our test application!