Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WithEvents in Interface class

Status
Not open for further replies.

JJR

Programmer
Apr 11, 2001
180
NL
Hi,

I, ve got a Business layer component which implements an interface from a interface component.

Now I would also like to add withevents, but I don't know where to place the definition of the event or if this is at all possible (couldn't find it in the MSDN).

If I put the definition in the interfaceclass and try to raise the event in the businessclass this doesn't work, because the businessclass doesn't know the event. If I put the definition in both classes, I get an error on my 'Set' statement and it says "Object or class does not support the set of events".

I'm out of options here...

Here 's an example of what I'm trying to do:

Code:
'Project: Blayer
'Class: BLClass
'Code:

Option Explicit

Public Event SaySomething(ByVal What As String)

Implements Iface.IClass

Private Function IClass_RaiseSomeEvent(ByVal Message As String) As Boolean
   RaiseEvent SaySomething(Message)
End Function



'Project: Iface
'Class: IClass
'Class: Dummy (empty)
'Code IClass:

Option Explicit

Public Event SaySomething(ByVal What As String)

Public Function RaiseSomeEvent(ByVal Message As String) As Boolean

End Function


'Project: Normal exe with a cmd button and a textbox
'Code:

Option Explicit
Private WithEvents m_oBL As Iface.IClass

Private Sub Command1_Click()
   
   Set m_oBL = New BLayer.BLClass
   
   Call m_oBL.RaiseSomeEvent(Text1.Text)

   Set m_oBL = Nothing
   
End Sub

Private Sub m_oBL_SaySomething(ByVal What As String)
   MsgBox What
End Sub

If anybody can make sense out of the above and help me, I'm a glad person.

Jordi Reineman
 
Hi JJR,

I'm in a hurry so I apologize for not looking at your example thoroughly. I notice that you've got the event declared in both the Interface and the concrete class (BLclass). You cannot declare/raise events in an Interface. If you remove event stuff from the Interface class, and keep it only in the concrete BLClass, you should be on your way.

Hope it helps.

 
Hi Geekett,

Thanx for your reply, but I've tried that and you run in to another problem because when you try to use the keyword withevents in the decleration part of the module like in:

Private WithEvents m_oBL As Iface.IClass

VB will tell you on compilation that the interface class doesn't expose events, so the withevents keyword is invalid.

Anyone else??

Jordi Reineman

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top