Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I implement an event in an Interface?

Posted on 2003-02-25
4
Medium Priority
?
245 Views
Last Modified: 2010-04-17
Is it possible in VB6.0 to implement events in an interface? I've got an ActiveX dll with a base class and an inherited class (ITest and test_1). I want the inherited class to be able to raise an event that is then handled by an event handler on my test form.

The code below gives me a run-time error '459' Object or class does not support the set of events.

Help!

' ITest
Public Event MyEvent()

Public Function DoSomething()
'
End Function

' test_1
Implements ITest

Public Event MyEvent()

Private Function ITest_DoSomething() As Variant
  RaiseEvent MyEvent
End Function

' form1
Private WithEvents myI As Project1.ITest

Private Sub Command1_Click()
  Set myI = New Project1.test_1
  myI.DoSomething
 
End Sub

Private Sub myI_MyEvent()
  MsgBox "done"
End Sub
0
Comment
Question by:SIMONJ
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
Da_Weasel earned 200 total points
ID: 8018584
Grabbed this from the MSDN.

"Important   The Implements feature does not support outgoing interfaces. Thus, any events you declare in the class module will be ignored."

Looks like 'Implements' ignores any outbound interfaces.  Which mean you either have to create events in each class or you have to create your own event system if you want to use something like this.  This requires you using subclassing, and various hooks depending on what you want to do.

"Create events in each class" method (best for simple systems with out complex requirements):
------------
ITest Class:
------------
Public Sub DoSomething()
'
End Sub
-------------
test_1 Class:
-------------
Implements ITest
Public Event MyEvent()
Public Sub ITest_DoSomething()
    RaiseEvent MyEvent
End Sub
-----------
Form1 Form:
-----------
Public WithEvents myTest As test_1
Private Sub Form_Load()
    Set myTest = New test_1
    myTest.ITest_DoSomething
End Sub
Private Sub myTest_MyEvent()
    MsgBox "What are you looking at!"
End Sub

"Create your own event system" method (best for complex systems that need event and handling):

xen:OS by k23 Productions is a great example of this.  Its available at www.xen-os.net in source and binary.  If you want to see a project that uses xen:OS then goto www.cloud9ine.com, we are currently developing iceFireXL and Cloud9ine using xen:OS.  All of these are open source via the GNU General Public Licence.
0
 

Author Comment

by:SIMONJ
ID: 8024049
Thanks Da_Weasel, you confirmed my fear that this was not possible.

Wanted to write my own wrapper for different versions of Outlook.Application and I thought a common interface was the way to go, but if I can't handle the events with a common handler then I'm back to square one. I guess I could use callbacks instead...
0
 
LVL 3

Expert Comment

by:Da_Weasel
ID: 8025428
no a prob, good luck with that....
0
 

Author Comment

by:SIMONJ
ID: 8032185
decided to go with MAPI in the end rather than automating Outlook. I'm still using an interface, but not bothering to handle events. The send method simply returns true or false depending on whether the user cancels the mail or sends.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Starting up a Project

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question