BUG: Parent Property Returns Invalid Object Type for UserControl (195755)
The information in this article applies to:
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q195755 SYMPTOMS
Visual Basic intrinsic controls support a Parent property that returns the
object of the parent hosting the control. Currently, this property is typed
as returning a Form object. However, if the control is hosted on a Visual
Basic UserControl or UserDocument, a Form object is not returned.
CAUSE
Because the Parent property is strongly typed as Form, it is possible to
early-bind to the object and call methods/properties through the vtable,
even through the object returned may not be a valid Form object. This can
cause application errors to occur at run-time.
RESOLUTION
To avoid problems caused by a mismatched object type, always perform late
binding when calling a method or property of an object returned from the
Parent property. For example, do not make an early bound call in the
following form:
Command1.Parent.Left = 10
Instead, declare a standard object variable and set a reference first. This
forces Visual Basic to use late binding and call each function by name
rather than by vtable position:
Dim oTmp As Object
Set oTmp = Command1.Parent
oTmp.Left = 10
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed
at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 5/12/2003 |
---|
Keywords: | kbBug kbcode KB195755 |
---|
|