Help with delegate callback error

F

Flomo Togba Kwele

I have a class which processes for a relatively long time. I want to enable
other classes which call this one to receive process messages if they wish.

The called routine (the one defining the delegate) is named CASSPrintSQL in
namespace CASS. The code is:

Private Delegate Sub DisplayMessage(ByVal msg As String)
Private _msgListener As DisplayMessage
....
Public Sub OnDisplayMessage(ByVal CallerMethod As DisplayMessage) '<== Error
_msgListener = CallerMethod
End Sub

The error is:
'CallerMethod' cannot expose type 'DisplayMessage' in namespace 'CASS' through
class 'CassPrintSQL'.

I do not understand this compilation error. Can anyone help? Thanks, Flomo
--
 
R

rowe_newsgroups

I have a class which processes for a relatively long time. I want to enable
other classes which call this one to receive process messages if they wish.

The called routine (the one defining the delegate) is named CASSPrintSQL in
namespace CASS. The code is:

Private Delegate Sub DisplayMessage(ByVal msg As String)
Private _msgListener As DisplayMessage
...
Public Sub OnDisplayMessage(ByVal CallerMethod As DisplayMessage) '<== Error
_msgListener = CallerMethod
End Sub

The error is:
'CallerMethod' cannot expose type 'DisplayMessage' in namespace 'CASS' through
class 'CassPrintSQL'.

I do not understand this compilation error. Can anyone help? Thanks, Flomo
--

You are exposing a private member of a class through a public method
(which is a no-no since it would override the private modifier).
Changing the delegate's modifier to public should fix the problem.

Thanks,

Seth Rowe
 
H

Herfried K. Wagner [MVP]

Flomo Togba Kwele said:
I have a class which processes for a relatively long time. I want to enable
other classes which call this one to receive process messages if they
wish.

The called routine (the one defining the delegate) is named CASSPrintSQL
in
namespace CASS. The code is:

Private Delegate Sub DisplayMessage(ByVal msg As String)

=> 'Public Delegate Sub...'.
Private _msgListener As DisplayMessage
...
Public Sub OnDisplayMessage(ByVal CallerMethod As DisplayMessage) '<==
Error
_msgListener = CallerMethod
End Sub

The error is:
'CallerMethod' cannot expose type 'DisplayMessage' in namespace 'CASS'
through
class 'CassPrintSQL'.

I do not understand this compilation error. Can anyone help? Thanks, Flomo

See above. The /public/ method exposes a parameter of type
'DisplayMessage', which requires the delegate type 'DisplayMessage' to be
visible outside the class too.
 
F

Flomo Togba Kwele

Thanks to you both for getting me over that hump.

Now to be greedy - it compiles but does not work as I expected. After
instantiating the object to be called, which also handles the delegate, I issue
the following in the calling routine:

cass.OnDisplayMessage(AddressOf GetMessage)
....
Private Sub GetMessage(ByVal msg As String)
lblInfo.Text = msg
End Sub

where cass is the instance name of the called routine. In that routine I
defined:
Private Sub SendMessage(ByVal msg As String)
If _msgListener IsNot Nothing Then
_msgListener.BeginInvoke(msg, Nothing, Nothing)
End If
End Sub

I called the SendMessage routine with different messages 6 times and I can see
this in the debugger. But I do not get any output in the Label. Any ideas?

Thanks again, Flomo
--
I have a class which processes for a relatively long time. I want to enable
other classes which call this one to receive process messages if they wish.

The called routine (the one defining the delegate) is named CASSPrintSQL in
namespace CASS. The code is:

Private Delegate Sub DisplayMessage(ByVal msg As String)
Private _msgListener As DisplayMessage
...
Public Sub OnDisplayMessage(ByVal CallerMethod As DisplayMessage) '<==
Error _msgListener = CallerMethod
End Sub

The error is:
'CallerMethod' cannot expose type 'DisplayMessage' in namespace 'CASS' through
class 'CassPrintSQL'.

I do not understand this compilation error. Can anyone help? Thanks, Flomo



--
 
L

Luke Zhang [MSFT]

Hello, Flomo,

Is the delegate defined in a class or user control? I tested following code:

Public Class Class1


Public Delegate Sub DisplayMessage(ByVal msg As String)
Private _msgListener As DisplayMessage


Public Sub OnDisplayMessage(ByVal CallerMethod As DisplayMessage)
_msgListener = CallerMethod
End Sub


Public Sub SendMessage(ByVal msg As String)
If _msgListener IsNot Nothing Then
_msgListener.Invoke(msg)
End If
End Sub

End Class

And tested it in a win form application, it seems to work well.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
F

Flomo Togba Kwele

Thanks for responding, Luke.

The delegate is defined in a regular class (CassPrintSql) which does a lot of
processing. The calling routine is a UserControl providing the GUI interface.
That is the one which is supposed to display messages coming from CassPrintSql
(the one containing the delegate).

I used the BeginInvoke method on the delegate because some of the processes in
this class take more than a few minutes. If I don't use an asynchronous
delegate, the messages will be blocked until the entire class is complete.

I don't know why it didn't work as coded. Any ideas?

Thanks, Flomo
 
L

Luke Zhang [MSFT]

Hello,

If you just have a test, use invoke instead of beginInvoke(), what will
happen to the Messages?

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
F

Flomo Togba Kwele

Luke,

If I change from BeginInvoke to Invoke, the result is the same - no output to
GUI interface until the calling program is complete.

Flomo


--
 
L

Luke Zhang [MSFT]

Hello,

If you use a simple class instead of your original CassPrintSql, to define
the delegate, what will happen? I suspect other code in CassPrintSql may
cause the problem so that the delegate doesn't work correctly. I tested a
simple class on my side, and I didn't find the problem.

Sincerely,

Luke Zhang

Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top