Delegate to a shared method

Is it possible to have a delegate that points to a Class Method, or even a Shared Class Method? I have the following code and I keep getting told that the methods do not exist. The following code:

Converters( 0, 1 ) = AddressOf ColumnDefinition.NumberToCodeList

Results in a compiler error:

Type "ColumnDefinition" has no member named "NumberToCodeList"
Converters( 0, 1 ) = AddressOf ColumnDefinition.NumberToCodeList

The code is actually inside the class (which is called “ColumnDefinition”). If I try the following:

Converters( 0, 1 ) = AddressOf NumberToCodeList

I’m told “This Item does not exist”. Actually NumberToCodeList is a Method with the correct signature for the delegate. Converters is defined as follows:

Public Shared Property Converters(5,5) As DataConversion

I’d rather have a single set of Delegate functions and a single array of pointers to them. Rather than have to create and instantiate one for every instance of the class (which there could be quite a few of in the application). If I have to I will move them to a module, but logically they belong to the class as it is what defines the types that are being converted.

The delegate is:

Public Sub DataConversion(ColDef as ColumnDefinition, Row as Integer, Assigns Value as Variant)

and the method:

Public Sub NumberToCodeList(ColDef as ColumnDefinition, Row as Integer, Assigns Value as Variant)

Isn’t it ways the way. I spotted the error when I posted this message. Both the delegate and function contained a parameter with assigns against it. Which is the cause of the problem. The compiler doesn’t spot that the delegate definition contains assigns and doesn’t report it.

Hint for anyone else. Check for “Assigns” in your delegates. They don’t work (I understand why but you’ll go insane and waste a lot of time tracking down the error).

1 Like