Implement Interface and Events 
Author Message
 Implement Interface and Events

How can I raise a event from a class which implements a Interface class?

Example:
There is a  public event in an interface class  - IClass like this.

public events MyEvent()

A workingclass - clsWork implements the IClass. The first line in clsWork is

Implements IClass

Now the question is how to raise MyEvent from clsWork.

Regards



Sun, 29 Sep 2002 03:00:00 GMT  
 Implement Interface and Events
You cannot raise an event using the Implemented interface. Unfortunately
there is no way to implement the dispinterface that VB uses for events (in
your example it would be __IClass). You can confirm this by dragging the
compiled dll into OLE COM viewer.


Quote:
> How can I raise a event from a class which implements a Interface class?

> Example:
> There is a  public event in an interface class  - IClass like this.

> public events MyEvent()

> A workingclass - clsWork implements the IClass. The first line in clsWork
is

> Implements IClass

> Now the question is how to raise MyEvent from clsWork.

> Regards



Mon, 30 Sep 2002 03:00:00 GMT  
 Implement Interface and Events
You cannot raise events from an implemented class.  But, that would be a
great addition to a VB7 wish list.

Kirk Allen Evans


Quote:
> How can I raise a event from a class which implements a Interface class?

> Example:
> There is a  public event in an interface class  - IClass like this.

> public events MyEvent()

> A workingclass - clsWork implements the IClass. The first line in clsWork
is

> Implements IClass

> Now the question is how to raise MyEvent from clsWork.

> Regards



Mon, 30 Sep 2002 03:00:00 GMT  
 Implement Interface and Events
hi anthony,
    this is also a question which i have posted in other newsgroups, with
the same response...you can't.

    but i have also wondered whether there is a work around for this, and
although i have heard that there is a work around for not being able to
inherit events, i can not find it.

    however, i'll tell you my thoughts on creating a work-around, and you
might be able to expand on it.

    first, you have two classes, the generic class, and the specific
class...the specific class implements the generic class.
    the generic class holds an event which will need to be raised.

    what you can do is create a friend sub in the generic class which raises
the event...this friend sub would be invoked by the specific class using
delegation.

    however, the impact of this is that your specific class and your generic
class will have to be stored in a separate dll, so that your friend sub can
not be invoked by anything else other than what's in the scope of the dll.

    also, another issue to contend with, consider the following.
    if i have a variable such as:

    Dim WithEvents x as SpecificClass

    the event that is raised in the generic class won't be caught by x, so
what i suppose will have to be done is that you do something like the
following:

    Dim WithEvents x as SpecificClass
    Dim WithEvents x2 as GenericClass

    set x2=x

    and catch the events of both classes.

    NOTE:  i haven't actually coded this yet, this is just something that i
thought of, but haven't got around to looking at in more depth, yet.

    if you can think of a variation, or something totally different that
will allow us to work around inheriting events, i'd be very interested to
hear from you.

Hope this helped.


Quote:
> How can I raise a event from a class which implements a Interface class?

> Example:
> There is a  public event in an interface class  - IClass like this.

> public events MyEvent()

> A workingclass - clsWork implements the IClass. The first line in clsWork
is

> Implements IClass

> Now the question is how to raise MyEvent from clsWork.

> Regards



Sat, 05 Oct 2002 03:00:00 GMT  
 Implement Interface and Events
Hey guys, Andrew Marshall wrote an article about this exact issue in the
April 2000 article of the Visual Basic Programmer's Journal, using "event
classes" to overcome the problem.  Not sure if its online still or not but
if you go to their website, you can download the sample code from the
article at

www.vbpj.com using locator number VB0004 to download the issues code, which
has the article sample within it.  Hope it helps,

kristofer goss


Quote:
> hi anthony,
>     this is also a question which i have posted in other newsgroups, with
> the same response...you can't.

>     but i have also wondered whether there is a work around for this, and
> although i have heard that there is a work around for not being able to
> inherit events, i can not find it.

>     however, i'll tell you my thoughts on creating a work-around, and you
> might be able to expand on it.

>     first, you have two classes, the generic class, and the specific
> class...the specific class implements the generic class.
>     the generic class holds an event which will need to be raised.

>     what you can do is create a friend sub in the generic class which
raises
> the event...this friend sub would be invoked by the specific class using
> delegation.

>     however, the impact of this is that your specific class and your
generic
> class will have to be stored in a separate dll, so that your friend sub
can
> not be invoked by anything else other than what's in the scope of the dll.

>     also, another issue to contend with, consider the following.
>     if i have a variable such as:

>     Dim WithEvents x as SpecificClass

>     the event that is raised in the generic class won't be caught by x, so
> what i suppose will have to be done is that you do something like the
> following:

>     Dim WithEvents x as SpecificClass
>     Dim WithEvents x2 as GenericClass

>     set x2=x

>     and catch the events of both classes.

>     NOTE:  i haven't actually coded this yet, this is just something that
i
> thought of, but haven't got around to looking at in more depth, yet.

>     if you can think of a variation, or something totally different that
> will allow us to work around inheriting events, i'd be very interested to
> hear from you.

> Hope this helped.



> > How can I raise a event from a class which implements a Interface class?

> > Example:
> > There is a  public event in an interface class  - IClass like this.

> > public events MyEvent()

> > A workingclass - clsWork implements the IClass. The first line in
clsWork
> is

> > Implements IClass

> > Now the question is how to raise MyEvent from clsWork.

> > Regards



Mon, 07 Oct 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Implement Interface and Events

2. Implementing Interface Events...

3. Implementing Interface Events

4. How to implement event of an interface?

5. Implementing COM Interfaces that have events

6. Implement Interface that has events

7. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

8. Implementing an interface made from another interface

9. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

10. Implementing an interface made from another interface

11. Major bug with Interface Events and Shared Events

12. Implementing IUnknown interface in Access 2000 class

 

 
Powered by phpBB® Forum Software