Generic Object References and Late Binding

In situations in which the object you are instantiating doesn't provide a type library, or when you are unsure at design time precisely which object you need to reference, you can use a local variable dimensioned as the generic type of Object. Then you use the CreateObject or GetObject function to return an object reference to assign to the local generic object variable. For example:

Dim oObjVar As Object

Set oObjVar = CreateObject("myComponent.myClass")

VB6 has also added to the functionality of the CreateObject function by allowing you to pass the server machine name as a string parameter. (For details on how to use CreateObject and GetObject see Chapter 7, The Language Reference.)

Was this article helpful?

0 0

Post a comment