|
-
Sep 25th, 2000, 09:44 AM
#1
Is it possible to use events when useing Implements
Say for example i have an interface for Animals
Some basic functions in it like eat,sleep etc
Now i want some events for the animals like, Tired/Angry etc
Now i have a class called Dog
it implements Animal so i can use the functions and sub etc, but now i want the dog to raise the events that it is tired, however it seems i cannont get the event to work.
When i add the event only to the Interface(Animal) then
Private Withevents CAnminal as IAnimal
Set CAnimal = New CDog
i get an error "Class or object does not support the set of events."
Same thing happens if i just copy the event to the Dog class
Is there anyway of doing this? (slimey hacks are welcome =])
-
Sep 25th, 2000, 09:46 AM
#2
Fanatic Member
Je zou kunnen proberen om de add-in die een activex control kan maken te gebruiken. Die kan ook events maken.
-
Sep 25th, 2000, 09:59 AM
#3
Originally posted by oetje
Je zou kunnen proberen om de add-in die een activex control kan maken te gebruiken. Die kan ook events maken.
I have no need for a usercontrol, i want to be able to raise the events from the class, but the class wont let me raise events because i dont know how i can implement Events(or if its even possible).
PS. Post in English as more people might have use for your awnser, want to read it, dont understand Dutch
-
Sep 25th, 2000, 10:04 AM
#4
Fanatic Member
I wanted to tell that you can create a dummy user control to see how the events work.
-
Sep 25th, 2000, 10:12 AM
#5
I know how events work.
Its just that i cant raise events from classes that are implementations of my interface.
I want to define events in my interface and then be able to let the implementation of the interface raise an event.
I can raise an event from a normal class but not from an implementation because of the "Object or class does not support set of events." error
-
Sep 25th, 2000, 10:16 AM
#6
Fanatic Member
Ok, I thought you didn't know how to use the RaiseEvent stuff.
-
Sep 25th, 2000, 06:04 PM
#7
Addicted Member
Hi,
You cannot have events in the actual interface itself. There is no work around for this, it is just not possible.
You can however, have events in the class that implements the interface.
Hope this helps
Shaun
Web/Application Developer
VB6 Ent (SP5), Win 2000,SQL Server 2000
-
Sep 25th, 2000, 07:05 PM
#8
Yes, but if i wanted to raise events from the class, i have to declare it as itself and that would throw away the interface.
I guess ill just have to check a state in the class instead of raising an event. To bad this will make the code that much more unreadable.
-
Sep 25th, 2000, 10:09 PM
#9
Frenzied Member
OK, There Is a workaround for this.
Add 2 new Classes to your Project, a CAnimal and a CEventHandler
The Event Handler is a very Simle class used to Pass Events through from the Implemented Class
So In your CDog Add a Property Get Like this
Code:
Dim MyEvents as New CEventHandler
Public Property Get EventHandler() As CEventHandler
Set EventHandler = MyEvents
End Property
And Change all your RaiseEvent Angrys to Call Me.EventHandler.RaiseAngry and the same For RaiseEvent Tired.
Then Make a Wrapper Class For it all callse CAnimal
Code:
Dim MyAnimal As IAnimal
Dim WithEvents AnimalEvents As CEventHandler
'Make this the Default Property
'This way to make a new CDog We Just do
'Dim WithEvents Fido As CAnimal
'Set Fido = New CAnimal
'Fido = New CDog
'We Make it a Property Let so we can distinguish betwen Setting the Wrapper Class and Setting the Animal Property
Public Property Let Animal(New_Animal As IAnimal)
Set MyAnimal = New_Animal
End Property
Private Sub AnimalEvents_Tired()
RaiseEvent Tired
End Sub
Private Sub AnimalEvents_Angry()
RaiseEvent Tired
End Sub
'Put Your Properties And Methods Here And Pass them through to the MyAnimal Object
Then You Can Use the CAnimal Class and all its events By Setting it's Animal Property to whateer you like
-
Sep 26th, 2000, 05:18 AM
#10
Yes i was thinking about that as well.
Thanks for the help
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
|