Monday, April 12, 2010

Implementing COM with Visual Basic

All objects must support the IUnknown interface. IUnknown has three methods: 1. AddRef (called when you use the SET statement)
2. Release (called when you set an object variable = Nothing)
3. QueryInterface (checks to see if specific interfaces are supported)
• The IDispatch interface is used to expose an object’s methods and properties. It also inherits
the 3 functions from the IUnknown interface. IDispatch has 4 methods of its own:
1. GetTypeInfo
2. GetTypeInfoCount
3. GetIDsOfNames
4. Invoke
• Late Binding occurs when a reference to a specific object type is not made. In other
words, the variable is declared as type Object as in the following example: Dim objX as
Object
• Declaring a variable as VARIANT is also considered to be late binding.
• Early Binding occurs when a reference is made to a specific object type. At compile
time, the compiler is able to check all object references against information in the object’s
type library. The following is an example of early binding: Dim objY As
ADODB.Command
This type of binding also allows the compiler to optimize access to the object and results in
two types of early binding: dispID binding and Vtable binding. Vtable binding is faster and
more efficient than dispID because it makes fewer method calls to the IDispatch interface.
• The proper syntax for a pop-up menu in Visual Basic is Me.PopupMenu mnuMyMenu.
You can replace Me by the name of the form if you like. This code can be placed in either
the form’s MouseUp or MouseDown event and the menu should be invisible initially.
• An application’s HelpFile can be set programmatically using the Visual Basic APP object.
• The StatusBar control has a panels collection that begins with index 1, not 0. It has two
styles: sbrNormal and sbrSimple. When using the simple style, use the SimpleText prop
erty to provide messages in the one, continuous status bar. If sbrNormal is chosen, on the
other hand, use the Text property to issue messages in one or more of the panels.
• The proper syntax for the TreeView control is:
Treeview.Nodes.Add(Relative], [Relationship], [Key], [Text], [Image], [Selected Image] )as node
• The ListView control can sort information by using the following properties: Sorted,
SortKey and SortOrder.
• DHTML is supported by Microsoft Internet Explorer 4.x or higher. DHTML is a clientbased
solution for applications deployed over the Internet.
• Internet Information Server (IIS) uses web classes and Active Server Pages (ASP). IIS
is a server-side solution for applications deployed over the Internet. Clients using web
browsers make requests to the IIS server and the server replies with responses
(WriteTemplate method, for example).
• DHTML applications generate a .HTM file and a compiled .DLL file.
ActiveX documents generate .VBD and .DLL (or .EXE) files.
• A connection to a database must be established and open before any transactions or execution
statements can be issued: Cnn.Open must precede those which follow
Cnn.BeginTransCmd.Execute


• Use the FRIEND keyword instead of Private or Public when you want class interfaces
(properties, methods) to be accessible ONLY to other classes in the same project.
• Private members cannot be used outside of the class.
• Friend members cannot be used outside of the component.
• Public members are available to use outside of the class and component.