|
-
May 4th, 2001, 12:17 PM
#1
Thread Starter
New Member
RaiseEvent and com interface
i made a class with an event that works just fine.
After i try to make a com interface between the class and a form, the raiseevent won't work anymore.
I get the errormessage:
Object or class does not support the set of events
Here is the code:
' the class named clsTest
Option Explicit
Implements iTest
Public mvarname As String 'local copy
Public mvaryear As Integer 'local copy
Public Event filled()
Public Sub iTest_fil(ByVal name As String, ByVal year As Integer)
mvarname = name
mvaryear = year
RaiseEvent filled
End Sub
Public Property Let iTest_year(ByVal vData As Integer)
mvaryear = vData
End Property
Public Property Get iTest_year() As Integer
year = mvaryear
End Property
Public Property Let iTest_name(ByVal vData As String)
mvarname = vData
End Property
Public Property Get iTest_name() As String
name = mvarname
End Property
'the interface named iTest
Option Explicit
Private mvarname As String 'local copy
Private mvaryear As Integer 'local copy
Public Event filled()
Public Sub fil(ByVal name As String, ByVal year As Integer)
End Sub
Public Property Let year(ByVal vData As Integer)
End Property
Public Property Get year() As Integer
End Property
Public Property Let name(ByVal vData As String)
End Property
Public Property Get name() As String
End Property
'the form
Option Explicit
Public WithEvents myTest As iTest
Private Sub Command1_Click()
myTest.fil Text1.Text, Text2.Text
End Sub
Private Sub Form_Load()
Set myTest = New clstest
End Sub
Private Sub myTest_filled()
MsgBox "filled"
End Sub
Anyone any idea why the raiseevent doesn't work anymore?
Thanks anyway.
-
May 4th, 2001, 01:13 PM
#2
Addicted Member
Try removing the line Public Event Filled() from the clsTest, since you've already defined it in iTest
-
May 9th, 2001, 04:01 AM
#3
You can't declare an event in an Interface component (ITest), nor can you capture events from an interface.
One way to get around it is to have a second object (clsEventRaiser) that actually raises the event, the interface (ITest) passes out through a property in clsEventRaiser (ITest.EventRaiser), your client code (TestHarness) takes a withevents to the clsEventRaiser object. When the event is to be fired the ITest calls a method (RaiseTestEvent) in the clsEventRaiser, the clsEventRaiser then raises the event and the test harness captures it.
this is a long work around but because an event requires VB to add a lot of code in at compile time, when you implement an interface definition, this code dosn't get included. the practical up shot is it won't work.
- gaffa
-
Aug 7th, 2001, 01:54 AM
#4
Lively Member
events and implements
You'd have thought that it would though - essentially, what is the difference between a method, property and event - just the way that they're "raised".
When you implement an interface in your object code, it puts in all the other objects, so why not put in the events that have been declared in your interface just as if you'd written them in the code.
bit of an oversight methinks...
(unless it's something that COM doesn't support...)
-
Aug 7th, 2001, 07:48 AM
#5
Events are more like notification and methods are more action oriented. In your class you could place code immediately after the iTest_fil and it would execute the same as the code in your event, or you could just set the Year and Name through the properties and it wouldn't fire. Events give the user of the object the ability to write code for when something happens for that instance of the object. Like you could have an Error event so whenever an error happened it was raised then the user of the class could just write code to handle all errors in the error event no matter where they were raised and the the code would be for just that instance not all of the objects. Thats a poor example but I tried...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|