Implementing Interface Events... 
Author Message
 Implementing Interface Events...

Hi,

I've created an interface containing an event...

Interface ITest
  Sub Test()
  Event TestEvent()
End Interface

Then I implemented it thus...

Public Class Class1
        Implements ITest
        Public Event TestEevent() Implements ITest.TestEvent

        Public Sub Test() Implements ITest.Test
                RaiseEvent TestEvent()
        End Sub
End Class

I then created a client and withevents'ed a variable to Class1

Dim WithEvents oClass as ClassLibrary1.Class1

Sub Main()
 oClass=new ClassLibrary1.Class1
 oClass.Test()
end sub

Private Sub MyHandler() Handles CLassLibrary1.TestEvent
 MessageBox.Show("Event Handled")
End Sub

Seems OK?... WRONG ! when I run it a get System.TypeLoadException when
it tries to create the ClassLibrary1.Class1 class.

Does anyone have any idea why ?  BTW I'm using Beta 2...

Thanks,

James Goode



Mon, 12 Jul 2004 00:12:14 GMT  
 Implementing Interface Events...
Here, I'm also using Beta2:
I re wrote this code which is just equivilent to what u wrote, I get no
errors and the interface's event is implemented with no problem.
(Every thing is inside class called Class1 and my app's name is
WindowsApplication1)
Read this code:
Interface Itest

    Sub Test()

    Event TestEvent()

End Interface

Class ClassA

    Implements Itest

    Public Event TestEvent() Implements
WindowsApplication1.Form1.Itest.TestEvent

    Public Sub Test() Implements WindowsApplication1.Form1.Itest.Test

        RaiseEvent TestEvent()

    End Sub

End Class

Private WithEvents c As ClassA

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

    c = New ClassA()

    c.Test()

End Sub

Private Sub c_TestEvent() Handles c.TestEvent

    MessageBox.Show("hello from implemented event")

End Sub


Quote:
> Hi,

> I've created an interface containing an event...

> Interface ITest
>   Sub Test()
>   Event TestEvent()
> End Interface

> Then I implemented it thus...

> Public Class Class1
> Implements ITest
> Public Event TestEevent() Implements ITest.TestEvent

> Public Sub Test() Implements ITest.Test
> RaiseEvent TestEvent()
> End Sub
> End Class

> I then created a client and withevents'ed a variable to Class1

> Dim WithEvents oClass as ClassLibrary1.Class1

> Sub Main()
>  oClass=new ClassLibrary1.Class1
>  oClass.Test()
> end sub

> Private Sub MyHandler() Handles CLassLibrary1.TestEvent
>  MessageBox.Show("Event Handled")
> End Sub

> Seems OK?... WRONG ! when I run it a get System.TypeLoadException when
> it tries to create the ClassLibrary1.Class1 class.

> Does anyone have any idea why ?  BTW I'm using Beta 2...

> Thanks,

> James Goode



Mon, 12 Jul 2004 04:32:51 GMT  
 Implementing Interface Events...
Muhammad,

The difference in your code is that the class is in the same project... If
you move it to a separate DLL you will experience the same bug.. (fixed in
RTM)...

Cheers
Daniel


Quote:
> Here, I'm also using Beta2:
> I re wrote this code which is just equivilent to what u wrote, I get no
> errors and the interface's event is implemented with no problem.
> (Every thing is inside class called Class1 and my app's name is
> WindowsApplication1)
> Read this code:
> Interface Itest

>     Sub Test()

>     Event TestEvent()

> End Interface

> Class ClassA

>     Implements Itest

>     Public Event TestEvent() Implements
> WindowsApplication1.Form1.Itest.TestEvent

>     Public Sub Test() Implements WindowsApplication1.Form1.Itest.Test

>         RaiseEvent TestEvent()

>     End Sub

> End Class

> Private WithEvents c As ClassA

> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click

>     c = New ClassA()

>     c.Test()

> End Sub

> Private Sub c_TestEvent() Handles c.TestEvent

>     MessageBox.Show("hello from implemented event")

> End Sub



> > Hi,

> > I've created an interface containing an event...

> > Interface ITest
> >   Sub Test()
> >   Event TestEvent()
> > End Interface

> > Then I implemented it thus...

> > Public Class Class1
> > Implements ITest
> > Public Event TestEevent() Implements ITest.TestEvent

> > Public Sub Test() Implements ITest.Test
> > RaiseEvent TestEvent()
> > End Sub
> > End Class

> > I then created a client and withevents'ed a variable to Class1

> > Dim WithEvents oClass as ClassLibrary1.Class1

> > Sub Main()
> >  oClass=new ClassLibrary1.Class1
> >  oClass.Test()
> > end sub

> > Private Sub MyHandler() Handles CLassLibrary1.TestEvent
> >  MessageBox.Show("Event Handled")
> > End Sub

> > Seems OK?... WRONG ! when I run it a get System.TypeLoadException when
> > it tries to create the ClassLibrary1.Class1 class.

> > Does anyone have any idea why ?  BTW I'm using Beta 2...

> > Thanks,

> > James Goode



Fri, 16 Jul 2004 18:33:03 GMT  
 Implementing Interface Events...
This was a bug that is now fixed in RTM

Cheers
Daniel


Quote:
> Hi,

> I've created an interface containing an event...

> Interface ITest
>   Sub Test()
>   Event TestEvent()
> End Interface

> Then I implemented it thus...

> Public Class Class1
> Implements ITest
> Public Event TestEevent() Implements ITest.TestEvent

> Public Sub Test() Implements ITest.Test
> RaiseEvent TestEvent()
> End Sub
> End Class

> I then created a client and withevents'ed a variable to Class1

> Dim WithEvents oClass as ClassLibrary1.Class1

> Sub Main()
>  oClass=new ClassLibrary1.Class1
>  oClass.Test()
> end sub

> Private Sub MyHandler() Handles CLassLibrary1.TestEvent
>  MessageBox.Show("Event Handled")
> End Sub

> Seems OK?... WRONG ! when I run it a get System.TypeLoadException when
> it tries to create the ClassLibrary1.Class1 class.

> Does anyone have any idea why ?  BTW I'm using Beta 2...

> Thanks,

> James Goode



Fri, 16 Jul 2004 18:15:20 GMT  
 Implementing Interface Events...
Thanks for your help folks.
Will retry this code with the release version.

Cheers,

James.



Sat, 17 Jul 2004 17:39:26 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Implementing Interface Events

2. How to implement event of an interface?

3. Implementing COM Interfaces that have events

4. Implement Interface and Events

5. Implement Interface and 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