How to Debug Typelib ShadowingLast reviewed: October 30, 1995Article ID: Q129867 |
The information in this article applies to:
SUMMARYIf an object is defined by the same name in more than one type library or object library, and a reference to both of them is chosen, Visual Basic uses the definition provided by the application listed higher in the Available References Box of the References Dialog. This article explains how to deal with these libraries and this behavior.
MORE INFORMATION
What Is an Object Library?An Object Library is a file with an .OLB extension that provides information to OLE Automation controllers (like Visual Basic) about available OLE Automation objects. The Object Browser can be used to examine the contents of an object library to get information about the objects provided.
What is a Type Library?A Type Library is a file or component within the object library that contains the OLE Automation standard descriptions of exposed objects, properties, and methods. How to Make Another Application's Objects Available to Your Application Another application's objects can be made available in your code by setting a reference to that application's object library. This can be done by choosing References from the Tools menu to bring up the References dialog box. Then you can select from a list of references displayed in the Available References box. To view these objects, choose Object Browser from the View menu. When you refer to an object in code, Visual Basic searches each application selected in the References dialog box in the order the applications are displayed. If two applications use the same name for an object, Visual Basic uses the definition provided by the application listed higher in the Available References box.
What to Do If the Object You Want Lies Further Down in the ListIf the object you actually want is defined in an object library futher down in the reference list, you can:
ExampleFor example, say you have the following code in an add-in:
Dim ft As Object Dim ct As ControlTemplate Dim oprop As Property ' VBInstance is instance passed to add-in Set ft = VBInstance.Application.ActiveProject.ActiveForm ' Select first control on the form: Set ct = ft.ControlTemplates.Item(0) ' Generates Type Mismatch error when oprop is of type Property. For Each oprop In ct.Properties Debug.print oprop.Name NextThe Property object is defined both in the DAO and the VBIDE object libraries. If DAO appears ahead of VBIDE in the reference list, a "Type Mismatch" error is generated at the For statement. This occurs because VBIDE's Property object that is actually being used is shadowed by DAO's Property object. Choose one of the following solutions as a remedy:
|
Additional reference words: 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |