Previous | Index | Next 

[PRB] Compilation errors with classes or usercontrols that expose events with same name as other members and that are used to define an interface

In VB6 it is legal to define a class that exposes an event with same name as a property or method, as in the following case:

        ' inside the Widget class
        Public Event FormatText()

        Public Sub FormatText()
            ' …
        End Sub

VB Migration Partner handles this case quite nicely and automatically generates a different name for the property or the method:

        Public Class Widget
Public Event FormatText() Public Sub FormatText_RENAMED() ' … End Sub End Class

However, a problem arises if the class appears in an Implements clause elsewhere in the project and therefore must be rendered as an interface. (This problem also arises if the class is marked with a ClassRenderMode pragma with Interface or ClassAndInterface argument.). In this case VB Migration Partner generates an incorrect Implements statement for the method, as in the following example:

        Public Class WidgetClass
            Implements Widget    ' error #1

            Public Event FormatText()
            
            Public Sub FormatText_RENAMED() Implements Widget.FormatText    ' error #2
                ' …
            End Sub
        End Class
  
        Public Interface Widget
            Sub FormatText()
        End Interface

The two statements marked with a comment cause the following compilation errors:

        Class 'Widget' must implement 'Sub FormatText_RENAMED()' for interface 'Widget'

        'FormatText_RENAMED' cannot implement 'FormatText' because there is no matching 
        sub on interface 'Widget'

The same two compilation errors also appear in any other class that contains an “Implements Widget” statement.

There is a simple workaround for this issue: just insert the following project-level PostProcess pragma somewhere in the Widget class:

        '## project:PostProcess "Widget\.FormatText", "$0_RENAMED"

 

Previous | Index | Next