PRB: Error 459 Trying to Use Alternate Object Interface
ID: Q172329
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0
-
Microsoft Visual Basic Control Creation, Learning, Professional, and Enterprise Editions for Windows, version 5.0
SYMPTOMS
You get run-time error 459 "Object or Class does not support the set of
elements" when assigning an object of class "A" to an object variable of
class "B" in order to use an alternate interface.
CAUSE
The base class you are implementing in your object defines an Event object
and your object variables are declared using the WithEvents keyword. The
Visual Basic versions listed above do not support events in inherited
interfaces.
RESOLUTION
This is a limitation of the versions of Visual Basic listed above.
STATUS
This behavior is by design.
MORE INFORMATIONSteps to Reproduce Behavior
- Create a form with a command button and two class modules (Base_Class
and Derived_Class).
- Add the following code to the Base_Class class module:
Event Alert(ByVal Msg As String)
Public Sub PostAlert(ByVal Msg As Msg)
End Sub
- Add the following code to the Derived_Class class module:
Implements Base_Class
Event Alert(ByVal Msg As String)
Private Sub Base_Class_PostAlert(ByVal Msg As String)
RaiseEvent Alert(Msg)
End Sub
- In the form module, add the following code:
Dim WithEvents objDC As Derived_Class, WithEvents objBC As Base_Class
Sub Command1_Click()
Set objDC = New Derived_Class
Set objBC = objDC ' error 459 occurs on this line
BC.PostAlert "Some Message"
Set objBC = Nothing
Set objDC = Nothing
End Sub
Sub DC_Alert(ByVal Msg As String)
MsgBox Msg
End Sub
Notes:
Additional query words:
WithEvents Implements kbdse kbDSupport kbVBp kbVBp500 kbVBp600
Keywords : kbGrpVBDB
Version :
Platform : WINDOWS
Issue type : kbprb
|