What steps need to be taken to create a COM Component?
Wednesday 27 February 2002 2:30 AM
Creating COM component in VB6 question
I hope you can help. I'm a C++ guy switching a little over into VB cause
it's so much faster to develop. Some months back I've built a small
ActiveX helper component that is in use with a number of programs at
various clients' sites. They now want me to improve something which
requires a change to the public interface of the ActiveX component. From
my C++ days I know what that would entail in terms of the IDL file and the
interface definitions. I would add a second interface that inherits from
the first, so that the original interface is immutable. Version 1 programs
would continue to use the original interface, Version 2 programs would use
the new interface which has everything the old one had, plus. Now how do
you do that in VB? And how do I set the Component properties in the
project properties? I appreciate any info you can send me, or references
to websites, or even just the title to the perfect book.
There are 5 things you need to do to add a property into an ActiveX
1. Declare a variable to allocate space for the property (at the very top of
Dim NameOfPerson As
2. Add the property procedures.
Choose Add Procedure from the Tools menu and add a Public Property called
Two procedures will appear - Get and Let.
Change Variant to the data type you need. For this example, we are using
Strings, so change the word 'Variant' to 'String'.
3. Write the code.
In the Get procedure, write this code:
YourName = NameOfPerson
When the program requests the property, the control will return the value of
NameOfPerson to the program.
In the Let procedure, write this code:
NameOfPerson = vNewValue
4. Property Bag. So the program knows at runtime what properties have been
set at design-time, you need to store the properties in something called the
UserControl_ReadProperties(PropBag As PropertyBag)
NameOfPerson = PropBag.ReadProperty("YourName", "Martin")
UserControl_WriteProperties(PropBag As PropertyBag)
I have used "Martin" as the default value. The name of the property
has to be held in quotes as a string.
5. You may also want to specify a default value for the property, use this
code to do that:
NameOfPerson = "Martin"
Martin Allen 1999 - 2011. Last updated
Tuesday 09 August 2011 08:08:57 PM +0100.