CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Location
    Singapore
    Posts
    72

    RaiseEvent for array of objects

    I have a class module (A) that raise events. In my app, I create an array of objects of type class A in a form. VB6 documentation says I cannot do such things:

    Dim withevents arrA(4) as A

    while i understand (sort of ) the reason behind this (connection and stuff), how else can i capture the events of such array of objects implementation. Currently, i am using a not-so elegant workaround

    dim withevents obj1 as A
    dim withevents obj2 as A
    dim withevents obj3 as A
    dim withevents obj4 as A
    dim arrA(4) as new A


    '''
    set obj1 = arrA(0)
    set obj2 = arrA(1)
    set obj3 = arrA(2)
    set obj4 = arrA(3)

    where arrA() is the array of objects of type class A. The problem is the array size has to be fixed while i want it dynamic. The events object variables has to be incremented/decremented.

    Setting reference for each arrA() element is not too good, because all objects can generate events simultaneously.

    Probably an ActiveX control will solve the problem but i am trying to avoid that.

    appreciate any help/suggestion.




  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: RaiseEvent for array of objects

    I did this with an equally inelegant solution:

    * Make a class with the class wizard which is a collection class for your objects.
    * Give this collection class an event
    * Give the object class a reference to its parent collection and a friend sub in that parent which raises the event.

    There doesn't seem to be a much better way,

    HTH,
    D.

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured