开发者

Run-time error 459 when using WithEvents with a class that implements another

I am developing a VBA project in Word and have encountered a problem with handling events when using a class that implements another.

I define an empty class, IMyInterface:

Public Sub Xyz()
End Sub

Public Event SomeEvent()

And a class, MyClass that implements the above:

Implements IMyInterface

Public Event SomeEvent()

Public Sub Xyz()
  ' ... code ...
  RaiseEvent SomeEvent
End Sub

Private Sub IMyInterface_Xyz()
   Xyz
End  Sub

If I create a third class, OtherClass, that declares a member variable with the type of the interface class:

Private WithEvents mMy As IMyInterface

and try to initialize this variable with an instance of the implementing class:

Set mMy = New MyClass

I get a run-time error '459': This component doesn't support this set of events.

The MSDN page for this error message states:

"You tried to use a WithEvents variable with a component that can't work as an event source for the specified set of events. For example, you may be sinking events of an object, then create another object that Implements the first object. Although you might think you could sink the events from the implemented object, that isn't automatically the case. Implements only implements an interface for methods and properties."

The above pretty much sums up what I'm trying to do. The wording, "that isn't automatically the case", rather than "this is flat-out impossible", seems to suggest that ther开发者_高级运维e is some bit of manual work I need to do to get it to work, but it doesn't tell me what! Does anybody know if this is possible in VBA?


Apparently Events are not allowed to be passed through an interface class into the concrete class like you want to using "Implements". In this article it states: "Event declarations of the abstract interface are not included in the interface that is inherited by concrete classes. I haven't found anywhere that this has been acknowledged as a bug; however, it does seem to be one."

Here is the link to the source: http://www.devx.com/getHelpOn/10MinuteSolution/20416

:-(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜