Click to See Complete Forum and Search --> : Looking for a workaround
Janitor
Aug 23rd, 2001, 12:38 PM
Here's the problem.
I have a program that is creating multiple instances of an ActiveX exe object. Since the user is given the option of choosing how many instances will be created, an array of these objects is the best bet. Unfortunately, arrays do do not work with the "WithEvents" statement (which is necessary for my program to interact with the sessions).
Is there a workaround for this? Creating and working with 10 variables is bulky and annoying.
Thanks.
Jay
jim mcnamara
Aug 23rd, 2001, 01:29 PM
You can reference the objects as members of a collection:
Dim MyColl as Collection
Dim MyObj as Object
For i = 1 to 10
Set MyObj = New whatever
MyColl.Add MyObj
Next i
'Then reference each one
For i = 1 to MyColl.Count
print Mycoll.Item(i).property1
next i
Janitor
Aug 23rd, 2001, 02:05 PM
Thanks for the idea of collections. It solves my initial problem beautifully, but another question has risen out of it.
How do I reference an event being raised by one of the instances in the collection?
Right now the code to take care of a single instance named GobjTimer is:
Private Sub GobjTimer_PeveNotify(ByVal LintEventCode As Integer)
' Do things
End Sub
Thanks again for the help
zeke_wpg
Aug 23rd, 2001, 08:53 PM
Couldn't you wrap up the collection as a class module with an event that passes back the id or instance of the ctl ??
Janitor
Aug 23rd, 2001, 09:49 PM
I am a little confused about what you are suggesting. This is the scenario of what I need.
I am using an ActiveX exe to carry out a series of internet related functions. To decrease the amount of time it takes to carry out these functions, I have created the ActiveX exe to handle the events asynchronously. X number of these sessions are created, and raise events to the calling program indicating various degrees of progress.
To track these "progress reports", the main program needs to accept the events and calculate the passed results.
What I need to do is find a way to spawn numerous instances of the ActiveX component, and wait for results as they are continuously sent back.
Using the suggestion of collections, I am able to create a dynamic number of these instances without having to create multiple variables. The problem is that there is no way to reference them. Normally, one would say variablename_event.
With the collection, however, collectionname.Item(index)_event does not work. I need a way to check for multiple occurrences of an event that are coming from multiple instances of the control.
Suggestions, anyone?
MartenKL
Feb 1st, 2005, 09:40 AM
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.
Dave Sell
Feb 1st, 2005, 10:07 AM
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 Dim WithEvents Object as ObjectType which implies a design-time restriction unmallable at run-time.
What you are asking for is something like: 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.
Calibra
Feb 1st, 2005, 10:48 AM
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.
Dave Sell
Feb 1st, 2005, 11:01 AM
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 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.
namrekka
Feb 16th, 2005, 03:45 AM
Once I had the same and rebuild it to an OCX.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.