Implementing COM Interfaces that have events 
Author Message
 Implementing COM Interfaces that have events

Okay.  I have a bunch of forms that are going to have to implement the same
interface.  The interface looks like:

Public Event OkClicked()
Public Event CancelClicked()

Private Sub LoadItem(Optional ByVal Identifier As String)
End Sub

Private Sub Show(ByVal Modal As FormShowConstants)
End Sub

I can implement the Subs without a problem, however, if I try to implement
the events I get errors.
I've tried declaring them as:

      Public Event IListForm_OkClicked()

but I get a syntax error saying that its an invalid Event name.   Ideas??



Mon, 26 Jul 2004 21:19:16 GMT  
 Implementing COM Interfaces that have events
Not quote....let me clarify.

I have a COM interface that I am implementing which has procedures and
events.  The problem comes when I'm IMPLEMENTING the interface inside a
component...not when I create an instance of the object that exposes the
interface.  (In face, I can't get the object to expose the interface sonce I
can't implement it)

It also might be a little odd that I'm implementing an interface inside of a
form, as opposed to a class.  However, forms are really just classes when
you think about it :)


Quote:
> It's been awhile since I've coded events, so forgive if this is
> incorrect.  I believe that you would say

> Private WithEvents aForm As IListForm

> Then you could code aForm_OkClicked().

> Hope this helps.

> Bruce Johnson
> TAG Consulting
> http://www.tagconsulting.com

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Mon, 26 Jul 2004 22:17:29 GMT  
 Implementing COM Interfaces that have events
You can not have underscore in Event name when you declare it.


Quote:
> Not quote....let me clarify.

> I have a COM interface that I am implementing which has procedures and
> events.  The problem comes when I'm IMPLEMENTING the interface inside a
> component...not when I create an instance of the object that exposes the
> interface.  (In face, I can't get the object to expose the interface sonce
I
> can't implement it)

> It also might be a little odd that I'm implementing an interface inside of
a
> form, as opposed to a class.  However, forms are really just classes when
> you think about it :)



> > It's been awhile since I've coded events, so forgive if this is
> > incorrect.  I believe that you would say

> > Private WithEvents aForm As IListForm

> > Then you could code aForm_OkClicked().

> > Hope this helps.

> > Bruce Johnson
> > TAG Consulting
> > http://www.tagconsulting.com

> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!



Mon, 26 Jul 2004 23:11:03 GMT  
 Implementing COM Interfaces that have events
Also even Form is an object you can not do it like this because of VB (.NET
here :-) )
You need to write class wrapper around this form. Declare it by form name
and use withevents keyword.


Quote:
> Not quote....let me clarify.

> I have a COM interface that I am implementing which has procedures and
> events.  The problem comes when I'm IMPLEMENTING the interface inside a
> component...not when I create an instance of the object that exposes the
> interface.  (In face, I can't get the object to expose the interface sonce
I
> can't implement it)

> It also might be a little odd that I'm implementing an interface inside of
a
> form, as opposed to a class.  However, forms are really just classes when
> you think about it :)



> > It's been awhile since I've coded events, so forgive if this is
> > incorrect.  I believe that you would say

> > Private WithEvents aForm As IListForm

> > Then you could code aForm_OkClicked().

> > Hope this helps.

> > Bruce Johnson
> > TAG Consulting
> > http://www.tagconsulting.com

> > *** Sent via Developersdex http://www.developersdex.com ***
> > Don't just participate in USENET...get rewarded for it!



Mon, 26 Jul 2004 23:17:04 GMT  
 Implementing COM Interfaces that have events
I know you can't.  However, that's the syntax that VB uses to denote that a
member is part of a specific interface.  Therefore, how do you implement the
Events that are declared in an interface if you can't have an event that
uses the standard syntax that denotes the member derives itself from an
interface?

I know that if I did this in .NET I could append "Implements
method.procedure" to the end of a procedure, but I can't do this project on
that platform.


Quote:
> You can not have underscore in Event name when you declare it.



> > Not quote....let me clarify.

> > I have a COM interface that I am implementing which has procedures and
> > events.  The problem comes when I'm IMPLEMENTING the interface inside a
> > component...not when I create an instance of the object that exposes the
> > interface.  (In face, I can't get the object to expose the interface
sonce
> I
> > can't implement it)

> > It also might be a little odd that I'm implementing an interface inside
of
> a
> > form, as opposed to a class.  However, forms are really just classes
when
> > you think about it :)



> > > It's been awhile since I've coded events, so forgive if this is
> > > incorrect.  I believe that you would say

> > > Private WithEvents aForm As IListForm

> > > Then you could code aForm_OkClicked().

> > > Hope this helps.

> > > Bruce Johnson
> > > TAG Consulting
> > > http://www.tagconsulting.com

> > > *** Sent via Developersdex http://www.developersdex.com ***
> > > Don't just participate in USENET...get rewarded for it!



Mon, 26 Jul 2004 23:37:56 GMT  
 Implementing COM Interfaces that have events
Actually, I don't.  These forms are all part of the same EXE.  I would only
have to build a wrapper if I wanted them public inside of a DLL


Quote:
> Also even Form is an object you can not do it like this because of VB
(.NET
> here :-) )
> You need to write class wrapper around this form. Declare it by form name
> and use withevents keyword.



> > Not quote....let me clarify.

> > I have a COM interface that I am implementing which has procedures and
> > events.  The problem comes when I'm IMPLEMENTING the interface inside a
> > component...not when I create an instance of the object that exposes the
> > interface.  (In face, I can't get the object to expose the interface
sonce
> I
> > can't implement it)

> > It also might be a little odd that I'm implementing an interface inside
of
> a
> > form, as opposed to a class.  However, forms are really just classes
when
> > you think about it :)



> > > It's been awhile since I've coded events, so forgive if this is
> > > incorrect.  I believe that you would say

> > > Private WithEvents aForm As IListForm

> > > Then you could code aForm_OkClicked().

> > > Hope this helps.

> > > Bruce Johnson
> > > TAG Consulting
> > > http://www.tagconsulting.com

> > > *** Sent via Developersdex http://www.developersdex.com ***
> > > Don't just participate in USENET...get rewarded for it!



Mon, 26 Jul 2004 23:42:18 GMT  
 Implementing COM Interfaces that have events
Check Email

Quote:
> I know you can't.  However, that's the syntax that VB uses to denote that
a
> member is part of a specific interface.  Therefore, how do you implement
the
> Events that are declared in an interface if you can't have an event that
> uses the standard syntax that denotes the member derives itself from an
> interface?

> I know that if I did this in .NET I could append "Implements
> method.procedure" to the end of a procedure, but I can't do this project
on
> that platform.



> > You can not have underscore in Event name when you declare it.



> > > Not quote....let me clarify.

> > > I have a COM interface that I am implementing which has procedures and
> > > events.  The problem comes when I'm IMPLEMENTING the interface inside
a
> > > component...not when I create an instance of the object that exposes
the
> > > interface.  (In face, I can't get the object to expose the interface
> sonce
> > I
> > > can't implement it)

> > > It also might be a little odd that I'm implementing an interface
inside
> of
> > a
> > > form, as opposed to a class.  However, forms are really just classes
> when
> > > you think about it :)



> > > > It's been awhile since I've coded events, so forgive if this is
> > > > incorrect.  I believe that you would say

> > > > Private WithEvents aForm As IListForm

> > > > Then you could code aForm_OkClicked().

> > > > Hope this helps.

> > > > Bruce Johnson
> > > > TAG Consulting
> > > > http://www.tagconsulting.com

> > > > *** Sent via Developersdex http://www.developersdex.com ***
> > > > Don't just participate in USENET...get rewarded for it!



Tue, 27 Jul 2004 02:39:00 GMT  
 Implementing COM Interfaces that have events
I just ran into this a couple of days ago; it can't be done:

    http://support.microsoft.com/default.aspx?scid=kb;en-us;Q172329


Quote:
> Okay.  I have a bunch of forms that are going to have to implement the
same
> interface.  The interface looks like:

> Public Event OkClicked()
> Public Event CancelClicked()

> Private Sub LoadItem(Optional ByVal Identifier As String)
> End Sub

> Private Sub Show(ByVal Modal As FormShowConstants)
> End Sub

> I can implement the Subs without a problem, however, if I try to implement
> the events I get errors.
> I've tried declaring them as:

>       Public Event IListForm_OkClicked()

> but I get a syntax error saying that its an invalid Event name.   Ideas??



Tue, 27 Jul 2004 04:14:27 GMT  
 Implementing COM Interfaces that have events
And I guess I could be bit more helpful, and tell you how I worked around
it:

Create a notification object:

Notifier.cls:

    Public Event OkClicked()
    Public Event CancelClicked()

    Public Sub SendOkNotification()
        RaiseEvent OkClicked()
    End Sub

    Public Sub SendCancelNotification()
        RaiseEvent CancelClicked()
    End Sub

Create your interface class thusly:

IListForm.cls:

    Public Sub Attach(n As Notifier)
    End Sub

    Private Sub LoadItem(Optional ByVal Identifier As String)
    End Sub

    Private Sub Show(ByVal Modal As FormShowConstants)
    End Sub

In your forms:

StateList.frm:

    Implements IListForm
    Private m_notifier as Notifier

    Private Sub IListForm_Attach(n As Notifier)
        Set m_notifier = n
    End Sub

    Private Sub IListForm_LoadItem(...)
        ...
    End Sub

    Private Sub IListForm_Show(...)
        ...
    End Sub

    Private Sub cmdOk_Click()
        ...
        m_notifier.SendOkNotification
        Unload Me
    End Sub

    Private Sub cmdCancel_Click()
        m_notifier.SendCancelNotification
        Unload Me
    End Sub

And in your controlling object:

Main.frm:

    Private WithEvents m_notifier as Notifier

    Private Sub Form_Initialize()
        Set m_notifier = New Notifier
    End Sub

    Private Sub cmdGetChoice_Click()
        Dim lf As IListForm
        Select Case True
            Case optState.Value
                Set lf = New frmStateList
            Case optProvince.Value
                Set lf = New frmProvinceList
            Case optFeudalHolding.Value
                Set lf = New frmFeudalList
        End Select
        lf.Attach m_notifier
        lf.Show vbModal
    End Sub

    Private Sub m_notifier_OkClicked()
        MsgBox "You clicked OK!"
    End Sub

    Private Sub m_notifier_CancelClicked()
        MsgBox "You clicked Cancel!"
    End Sub

Basically, instead of watching for events from the forms themselves, you
watch for them from a substitute object which you pass to the forms.


Quote:
> I just ran into this a couple of days ago; it can't be done:

>     http://support.microsoft.com/default.aspx?scid=kb;en-us;Q172329



> > Okay.  I have a bunch of forms that are going to have to implement the
> same
> > interface.  The interface looks like:

> > Public Event OkClicked()
> > Public Event CancelClicked()

> > Private Sub LoadItem(Optional ByVal Identifier As String)
> > End Sub

> > Private Sub Show(ByVal Modal As FormShowConstants)
> > End Sub

> > I can implement the Subs without a problem, however, if I try to
implement
> > the events I get errors.
> > I've tried declaring them as:

> >       Public Event IListForm_OkClicked()

> > but I get a syntax error saying that its an invalid Event name.

Ideas??


Tue, 27 Jul 2004 04:34:26 GMT  
 Implementing COM Interfaces that have events
Have a look at the following discussion :
http://news.devx.com/cgi-bin/dnewsweb.exe?utag=&group=vb.general&xrel...
124&cmd_related.x=34&cmd_related.y=10

(recompose the URL)

--
Van den Driessche Willy
For a work in progress :
http://users.skynet.be/wvdd2/index.html



Tue, 27 Jul 2004 05:27:55 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Implement COM interface

2. Implement COM interface...

3. Implementing Interface Events...

4. Implementing Interface Events

5. How to implement event of an interface?

6. Implement Interface and Events

7. Implement Interface and Events

8. Implement Interface that has events

9. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

10. Implementing an interface made from another interface

11. IMPLEMENTING AN INTERFACE MADE FROM ANOTHER INTERFACE

12. Implementing an interface made from another interface

 

 
Powered by phpBB® Forum Software