[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Events and array of server

Jim Mack

3/5/2012 9:55:00 PM

I know we can't do this:

Dim WithEvents Arry(1 To 4) As SomeAxServer

....but I really could use the functionality.

I've seen a couple of workarounds, but I'm not sure which is the best
approach from performance and convenience standpoints.

For a small, fixed-size array I could declare individual control
variables, and dispatch their events to a common servicing function
using an ID in place of an array index. But that gets bloated quickly
as the number increases, and won't work at all for an unknown (at
compile time) number of controls.

Is there a reasonable general case, where I can work with an unknown
number of such, and get reasonable performance without jumping through
a lot of hoops? What have you all done?

--
Jim


18 Answers

olde.sault

7/19/2011 5:58:00 AM

0

On Jul 19, 8:55 am, "DonH" <donlhumphr...@bigpond.com> wrote:
> "olde.sault" <olde.sa...@gmail.com> wrote in message
>
> news:bbfc2bae-18f4-4a0e-b8e2-3b087d8140d9@u6g2000prc.googlegroups.com...
> On Jul 19, 7:34 am, "DonH" <donlhumphr...@bigpond.com> wrote:
>
> > - until the next federal election?
> > After all, Gillard has only to tough it out until then, for the
> > electorate to face a stark choice, come the crunch. By then, that scary
> > Carbon Tax will be bedded down, and without Armageddon.
> > But can Abbott survive on negativity alone? And he's the one with an
> > obvious successor - Turnbull.
> > The federal ALP may have reached rock-bottom, poll-wise, so there is
> > nowhere else to go but up. And when/if that starts to happen...
> > WorkChoices anyone?
>
> Who is paying you you bray such nonsense or have you just been
> hypnotised by the bag of bones, GayBob?
>
> OS
>
> # No one is paying me nothing. Who is paying you?
>    A bit browned off, are you?
>    Ad hominem attacks are tiresome, and prove nothing, so if you can't reply
> to the substance of the posting, why bother?

"No one is paying me "anything" (not "nothing") However, not blaming
youse none, that's the tutoring by leftwing teachers.

OS

Clocky

7/19/2011 2:19:00 PM

0

olde.sault wrote:
> On Jul 19, 8:55 am, "DonH" <donlhumphr...@bigpond.com> wrote:
>> "olde.sault" <olde.sa...@gmail.com> wrote in message
>>
>> news:bbfc2bae-18f4-4a0e-b8e2-3b087d8140d9@u6g2000prc.googlegroups.com...
>> On Jul 19, 7:34 am, "DonH" <donlhumphr...@bigpond.com> wrote:
>>
>>> - until the next federal election?
>>> After all, Gillard has only to tough it out until then, for the
>>> electorate to face a stark choice, come the crunch. By then, that
>>> scary Carbon Tax will be bedded down, and without Armageddon.
>>> But can Abbott survive on negativity alone? And he's the one with an
>>> obvious successor - Turnbull.
>>> The federal ALP may have reached rock-bottom, poll-wise, so there is
>>> nowhere else to go but up. And when/if that starts to happen...
>>> WorkChoices anyone?
>>
>> Who is paying you you bray such nonsense or have you just been
>> hypnotised by the bag of bones, GayBob?
>>
>> OS
>>
>> # No one is paying me nothing. Who is paying you?
>> A bit browned off, are you?
>> Ad hominem attacks are tiresome, and prove nothing, so if you can't
>> reply to the substance of the posting, why bother?
>
> "No one is paying me "anything" (not "nothing") However, not blaming
> youse none, that's the tutoring by leftwing teachers.
>
> OS

Typical right-wing uneducated nutjobs giving lessons on grammar?
LOL, good one.


Karl E. Peterson

3/5/2012 11:55:00 PM

0

Jim Mack wrote on 3/5/2012 :
> I know we can't do this:
>
> Dim WithEvents Arry(1 To 4) As SomeAxServer
>
> ...but I really could use the functionality.
>
> I've seen a couple of workarounds, but I'm not sure which is the best
> approach from performance and convenience standpoints.
>
> For a small, fixed-size array I could declare individual control variables,
> and dispatch their events to a common servicing function using an ID in place
> of an array index. But that gets bloated quickly as the number increases, and
> won't work at all for an unknown (at compile time) number of controls.
>
> Is there a reasonable general case, where I can work with an unknown number
> of such, and get reasonable performance without jumping through a lot of
> hoops? What have you all done?

I tend to implement a callback interface. The downside, of course, is
that you have to explicitly teardown the circular reference.

Another method that's sort of ingenious in certain designs, is to
declare a notification object, and pass a reference to this to each of
your event generators. The event generators can then call a public
method of the notification object, passing a reference to themselves,
which is forwarded to the event sink as a parameter of the event.

It sounds nastier than it looks. <g>

http://vb.mvps.org/articles/ap...
http://vb.mvps.org/samples/...

--
..NET: It's About Trust!
http://vfre...


Larry Serflaten

3/6/2012 12:18:00 AM

0

Jim Mack wrote:
> Is there a reasonable general case, where I can work with an unknown
> number of such, and get reasonable performance without jumping through
> a lot of hoops? What have you all done?

You can create a class to source the events and use one instance of that object passed around to all of the unknown number of AxServers. If you are going to reference the AxServers by index, you might also identify the events by index (if that suits the situation) which makes the class easy to write. Something like the following:

'[EventServer class]
Public Enum MethodNames
RcvBytes
RcvACK
RcvError
End Enum

Public Event Notice(Method As MethodNames, Index As Long, Args As Variant)

Public Sub Notify(Method As MethodNames, Index As Long, Args As Variant)
RaiseEvent Notice(Method, Index, Args)
End Sub


'[EventSource class]
Public Index As Long
Public Events As EventServer

Public Sub TestEvent()
Events.Notify RcvACK, Index, 0
End Sub


'[Form1 form]
Private WithEvents Server As EventServer
Private Sources() As EventSource ' Unknown number of AxServers

Private Sub Form_Load()
Dim i&

' Init
Set Server = New EventServer
ReDim Sources(0 To 3) As EventSource
For i = 0 To 3
Set Sources(i) = New EventSource
Set Sources(i).Events = Server
Sources(i).Index = i
Next

' Test
Sources(1).TestEvent
Sources(3).TestEvent

End Sub

Private Sub Server_Notice(Method As MethodNames, Index As Long, Args As Variant)
Debug.Print "EVENT RCVD:", Method, Index, Args
End Sub


(Sorry for line breaks, I was in a hurry...)
LFS

Jim Mack

3/6/2012 12:32:00 AM

0

>> Is there a reasonable general case, where I can work with an unknown
>> number of such, and get reasonable performance without jumping through
>> a lot of hoops? What have you all done?
>
> I tend to implement a callback interface. The downside, of course, is
> that you have to explicitly teardown the circular reference.

"Callback" sounds very "in-process". Is that just shorthand?

> Another method that's sort of ingenious in certain designs, is to declare
> a notification object, and pass a reference to this to each of your event
> generators. The event generators can then call a public method of the
> notification object, passing a reference to themselves, which is
> forwarded to the event sink as a parameter of the event.
>
> It sounds nastier than it looks. <g>
>
> http://vb.mvps.org/articles/ap...
> http://vb.mvps.org/samples/...

The second version of that looks doable, but so I understand -- you'd
need a separate notify object for each event you want to raise? Or I
suppose you could also pass in an identifier for the specific event
you're 'raising', in addition to the object identifier?

It's starting to sound slow...

--
Jim


Jim Mack

3/6/2012 12:36:00 AM

0

> Jim Mack wrote:
>> Is there a reasonable general case, where I can work with an unknown
>> number of such, and get reasonable performance without jumping through
>> a lot of hoops? What have you all done?
>
> You can create a class to source the events and use one instance of that
> object passed around to all of the unknown number of AxServers. If you
> are going to reference the AxServers by index, you might also identify
> the events by index (if that suits the situation) which makes the class
> easy to write. Something like the following:
>
> '[EventServer class]
> Public Enum MethodNames
> RcvBytes
> RcvACK
> RcvError
> End Enum
>
> Public Event Notice(Method As MethodNames, Index As Long, Args As
> Variant)
>
> Public Sub Notify(Method As MethodNames, Index As Long, Args As Variant)
> RaiseEvent Notice(Method, Index, Args)
> End Sub
>
> '[EventSource class]
> Public Index As Long
> Public Events As EventServer
>
> Public Sub TestEvent()
> Events.Notify RcvACK, Index, 0
> End Sub
>
> '[Form1 form]
> Private WithEvents Server As EventServer
> Private Sources() As EventSource ' Unknown number of AxServers
>
> Private Sub Form_Load()
> Dim i&
>
> ' Init
> Set Server = New EventServer
> ReDim Sources(0 To 3) As EventSource
> For i = 0 To 3
> Set Sources(i) = New EventSource
> Set Sources(i).Events = Server
> Sources(i).Index = i
> Next
>
> ' Test
> Sources(1).TestEvent
> Sources(3).TestEvent
>
> End Sub
>
> Private Sub Server_Notice(Method As MethodNames, Index As Long, Args As
> Variant) Debug.Print "EVENT RCVD:", Method, Index, Args
> End Sub

Thanks! That also answers the question I asked Karl about raising
different events via the one event pathway.

--
Jim


Karl E. Peterson

3/6/2012 12:53:00 AM

0

on 3/5/2012, Jim Mack supposed :
>>> Is there a reasonable general case, where I can work with an unknown
>>> number of such, and get reasonable performance without jumping through a
>>> lot of hoops? What have you all done?
>>
>> I tend to implement a callback interface. The downside, of course, is that
>> you have to explicitly teardown the circular reference.
>
> "Callback" sounds very "in-process". Is that just shorthand?

Hmmm, well, now that you put it that way. <g> Yeah, I think I've only
used it like that myself. I didn't pick up on that you might be doing
it out of process.

>> Another method that's sort of ingenious in certain designs, is to declare a
>> notification object, and pass a reference to this to each of your event
>> generators. The event generators can then call a public method of the
>> notification object, passing a reference to themselves, which is forwarded
>> to the event sink as a parameter of the event.
>>
>> It sounds nastier than it looks. <g>
>>
>> http://vb.mvps.org/articles/ap...
>> http://vb.mvps.org/samples/...
>
> The second version of that looks doable, but so I understand -- you'd need a
> separate notify object for each event you want to raise? Or I suppose you
> could also pass in an identifier for the specific event you're 'raising', in
> addition to the object identifier?

You'd just define multiple events. Or, have the event in question be a
property of the event generator. The first would be the most
straight-forward, the second the more flexible, perhaps.

> It's starting to sound slow...

I think both of these are leaning towards the "convenience" end of the
spectrum. But you're really just passing a pointer around. (I guess
anytime objects move between processes, yeah, there's some grunt work
involved? I've just never done much of that.)

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

3/6/2012 12:57:00 AM

0

Jim Mack laid this down on his screen :
>> Jim Mack wrote:
>>> Is there a reasonable general case, where I can work with an unknown
>>> number of such, and get reasonable performance without jumping through a
>>> lot of hoops? What have you all done?
>>
>> You can create a class to source the events and use one instance of that
>> object passed around to all of the unknown number of AxServers. If you are
>> going to reference the AxServers by index, you might also identify the
>> events by index (if that suits the situation) which makes the class easy to
>> write. Something like the following:
>>
>> '[EventServer class]
>> Public Enum MethodNames
>> RcvBytes
>> RcvACK
>> RcvError
>> End Enum
>>
>> Public Event Notice(Method As MethodNames, Index As Long, Args As Variant)
>>
>> Public Sub Notify(Method As MethodNames, Index As Long, Args As Variant)
>> RaiseEvent Notice(Method, Index, Args)
>> End Sub
>>
>> '[EventSource class]
>> Public Index As Long
>> Public Events As EventServer
>>
>> Public Sub TestEvent()
>> Events.Notify RcvACK, Index, 0
>> End Sub
>>
>> '[Form1 form]
>> Private WithEvents Server As EventServer
>> Private Sources() As EventSource ' Unknown number of AxServers
>>
>> Private Sub Form_Load()
>> Dim i&
>> ' Init
>> Set Server = New EventServer
>> ReDim Sources(0 To 3) As EventSource
>> For i = 0 To 3
>> Set Sources(i) = New EventSource
>> Set Sources(i).Events = Server
>> Sources(i).Index = i
>> Next
>> ' Test
>> Sources(1).TestEvent
>> Sources(3).TestEvent
>> End Sub
>>
>> Private Sub Server_Notice(Method As MethodNames, Index As Long, Args As
>> Variant) Debug.Print "EVENT RCVD:", Method, Index, Args
>> End Sub
>
> Thanks! That also answers the question I asked Karl about raising different
> events via the one event pathway.

For out-of-process, this design could probably be quicker, as it's just
passing the parameters directly rather than an object pointer. The
object pointer is just more flexible at the sink, because you can query
any of its properties or call its methods at will.

I'd probably lean towards distinct events myself, too, just to avoid
the Select Case in the sink.

--
..NET: It's About Trust!
http://vfre...


Dee Earley

3/6/2012 10:24:00 AM

0

On 05/03/2012 21:54, Jim Mack wrote:
> I know we can't do this:
>
> Dim WithEvents Arry(1 To 4) As SomeAxServer
>
> ...but I really could use the functionality.
>
> I've seen a couple of workarounds, but I'm not sure which is the best
> approach from performance and convenience standpoints.
>
> For a small, fixed-size array I could declare individual control
> variables, and dispatch their events to a common servicing function
> using an ID in place of an array index. But that gets bloated quickly as
> the number increases, and won't work at all for an unknown (at compile
> time) number of controls.
>
> Is there a reasonable general case, where I can work with an unknown
> number of such, and get reasonable performance without jumping through a
> lot of hoops? What have you all done?

I've done this with a wrapper class that handles the events and uses a
private mechanism to notify the parent.
This can be direct calls to a global instance of the parent, calls to a
local referance to it (but requires explicit cleanup), or just handling
the events directly for its own instance.

--
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk...

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Jim Mack

3/6/2012 1:24:00 PM

0

> On 05/03/2012 21:54, Jim Mack wrote:
>> I know we can't do this:
>>
>> Dim WithEvents Arry(1 To 4) As SomeAxServer
>>
>> ...but I really could use the functionality.
>>
> I've done this with a wrapper class that handles the events and uses a
> private mechanism to notify the parent.
> This can be direct calls to a global instance of the parent, calls to a
> local referance to it (but requires explicit cleanup), or just handling
> the events directly for its own instance.

Larry posted, and Karl linked to, a way of doing this that doesn't
require an explicit teardown. Given that this must work out of process,
do you see an advantage to any method that requires that? Fewer trips
through the marshaller, etc?

I don't follow the reference to "just handling the events directly".
What method allows that?

--
Jim