tags:

views:

47

answers:

2

I have this interface

Interface IProDataSource

    Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
    Event starting_Sinc As DstartingHandler

End Interface

Trying to use the interface like this

Public Class DataSource : Implements IProDataSource

    Public Event starting_Sinc As DstartingHandler Implements IProDataSource.starting_Sinc
    Public Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)

End Class

Gives me the next error

Event 'starting_Sinc' cannot implement event 'starting_Sinc' on interface 'IProDataSource' because their delegate types 'DstartingHandler' and 'IProDataSource.DstartingHandler' do not match.

+1  A: 

The reason why is you now have 2 instances of the delegate DstartingHandler defined in your application. One inside of DataSource and the other inside of IProDataSource. The one in DataSource appears to be an error and deleting it should fix all of your problems.

EDIT

I tried the following code and it compiles

Class C1
    Implements IProDataSource

    Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class
JaredPar
I alreade try that and got the next error'starting_Sinc' cannot implement 'starting_Sinc' because there is no matching event on interface 'IProDataSource'
carlos
@carlos, the next step is that you need to expand the delegate arguments into the event as I showed in my updated answer. I'm not entirely sure why this is necessary off the top of my head though.
JaredPar
+1  A: 

You'll need to move the delegate declaration outside of the interface and declare it public. All types used by an interface must be public when the class that implements them is public. Necessarily so or the client code could never assign the event. Thus:

Public Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)

Interface IProDataSource
    Event starting_Sinc As DstartingHandler
End Interface

Public Class DataSource : Implements IProDataSource
    Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class

If you limit the accessibility of the class you can use your original approach:

Interface IProDataSource
    Delegate Sub DstartingHandler(ByVal sender As Object, ByVal e As EventArgs)
    Event starting_Sinc As DstartingHandler
End Interface

Friend Class DataSource : Implements IProDataSource
    Public Event starting_Sinc(ByVal sender As Object, ByVal e As System.EventArgs) Implements IProDataSource.starting_Sinc
End Class
Hans Passant
Hey !!! the first approach worked perfectly, the second one gives me yet an error but i wil go using the first one.Error 1 'starting_Sinc' cannot expose the underlying delegate type 'IProDataSource.DstartingHandler' of the event it is implementing outside the project through class 'DataSource'Thanks a lot !!!
carlos