Home All Groups Group Topic Archive Search About

Help with delegate callback error

Author
30 Apr 2007 5:17 PM
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
--

Author
30 Apr 2007 5:43 PM
rowe_newsgroups
Show quote Hide quote
On Apr 30, 1:17 pm, "Flomo Togba Kwele" <F...@community.nospam> wrote:
> 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
Author
30 Apr 2007 9:28 PM
Herfried K. Wagner [MVP]
"Flomo Togba Kwele" <Flomo@community.nospam> schrieb:
>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.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
Author
1 May 2007 12:07 AM
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
--

Flomo Togba Kwele wrote:

Show quoteHide quote
> 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



--
Author
1 May 2007 5:55 AM
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.
Author
1 May 2007 4:39 PM
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
Author
2 May 2007 6:41 AM
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.
Author
2 May 2007 9:13 PM
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


--
Author
4 May 2007 6:39 AM
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.
Author
7 May 2007 3:37 AM
Flomo Togba Kwele
Luke,

Thanks for the reply. I had to call CSS.

Flomo



Luke Zhang [MSFT] wrote:

Show quoteHide quote
> 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.
>
>