Results 1 to 4 of 4

Thread: Events in Interface Classes

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Events in Interface Classes

    I have an interface class that declares a Public Event.

    In my Implementation class, how do I implement that event so that clients of my implementation class can trap events raised?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Events in Interface Classes

    You don't do anything in an interface. An interface just contains a template that other classes can implement. The "events" are subs/funtions. This is an example
    VB Code:
    1. ' Interface IBanana
    2.  
    3. Public Sub GotBanana(ByRef pobjBanana As CBanana)
    4.     '
    5. End Sub
    6.  
    7. Public Sub BadBanana()
    8.     '
    9. End Sub

    and you implement it like this:
    VB Code:
    1. ' Class CMonkey
    2.  
    3. Implements IBanana
    4.  
    5. Private Sub IBanana_GotBanana(ByRef pobjBanana As CBanana)
    6.     EatBanana pobjBanana
    7. End Sub
    8.  
    9. Private Sub IBanana_BadBanana()
    10.     ThrowUp
    11. End Sub

    If on the other hand, by implement you mean raise the event/notification, you do it like this (from a class/module:
    VB Code:
    1. ' Module MEcosystem
    2.  
    3. ' Throw the event
    4. Public Sub GiveHimABanana(ByRef pobjMonkey As CMonkey, _
    5.                           ByRef pobjBanana As CBanana)
    6.     ' Reference the class implementing the event, not the interface
    7.     pobjMonkey.GotBanana pobjBanana
    8. End Sub

    Congrats on your 666th post BTW

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Events in Interface Classes

    VB does not support Events in "inherited" interfaces.

    PRB: Error 459 Trying to Use Alternate Object Interface

  4. #4

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Events in Interface Classes

    Thanks for the help people...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

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