Re: Looking for a workaround
I have the same problem and will do the following, if anyone has a better idea please let me know, i would like to have collections like controls collections in VB6 where an eventhandler includes the index of the object firing the event.
public class MyDll
private Owner as MyDllCollection
public id as Integer
public sub SetOwner(Value as MyDllCollection)
Owner=Value
end sub
public sub DoReport
'Do your report here
Owner.ChildComplete(Me)
end sub
end class
public class MyDllCollection
Inherits System.Collections.CollectionBase
public event Completed(index as integer)
Default Property Item(ByVal index As Integer) As MyDll
Get
Return CType(innerlist.Item(index), MyDll)
End Get
Set(ByVal Value As qServer)
innerlist.Add(Value)
End Set
End Property
public Function Add(ByVal Value As MyDll) As Integer
InnerList.Add(Value)
Value.SetOwner(Me)
Value.id=innerlist.IndexOf(Value)
Return innerlist.IndexOf(Value)
End Function
public sub ChildComplete(ByRef Value as MyDll)
raisevent Completed(Value.id)
end sub
end class
This requires som synchronisation as well but should do what you are asking for. I haven't tried it yet but it should work.
Re: Looking for a workaround
I believe this is technically outside the realm of what VB6 can handle. In order for a Parent object to listen for Events on a Child Object, you need to do a
VB Code:
Dim WithEvents Object as ObjectType
which implies a design-time restriction unmallable at run-time.
What you are asking for is something like:
VB Code:
Dim WithEvents CollectionOfObjects As (ObjectType or Collection)
which is not something VB6 was designed for.
This does not imply that you cannot reach your end goal, just that you will have to find another means of doing it.
Re: Looking for a workaround
Zeke is pointing to the right direction.
Why not wrap the ActiveX in an class module and define the event handlers in that class mod, and instead of creating an new activex object you could create an new class which in turn creates the activex and handles the events
and put these clas objects in an collection.
Re: Looking for a workaround
I think the issue at hand is changing the number of Objects that a Parent Object can listen to their Events.
At design time, you use the
VB Code:
Dim WithEvents Object As ObjectType
to tell the Parent Object that it should listen to the Events Raised by that Object.
He wants to change the number of Objects listened to at run time from 1 to say 3 or 4, and be able to know exactly which Object raised the Event.
You could make a single ActiveX Object to manage dynamically created aggregate objects, if you gave them all different names or something, but the original proposal is outside the bounds of VB6 functionality.
Re: Looking for a workaround
Once I had the same and rebuild it to an OCX.