delegates + functions

.paul.

Well-known member
Joined
May 22, 2007
Messages
212
Programming Experience
1-3
[resolved] delegates + functions

i've written some delegates that work well with subs but not with functions (see attached code). what am i doing wrong? i can't find any more information on MSDN

VB.NET:
Private Delegate Function listview_items_countCallback() As Integer

    Public Function listview_items_count() As Integer
        If Me.listview.InvokeRequired Then
            Me.listview.Invoke(New listview_items_countCallback(AddressOf listview_items_count))
        Else
            listview_items_count = Me.listview.Items.Count
        End If
    End Function
 
Last edited:
Dont use old style VB6 function returns. Use the new "Return" style. It will help you see where your code is flawed. Not all of your code paths here return a value

VB.NET:
Private Delegate Function listview_items_countCallback() As Integer

    Public Function listview_items_count() As Integer
        If Me.listview.InvokeRequired Then
            [B]Return [/B][B]DirectCast[/B](Me.listview.Invoke(New listview_items_countCallback(AddressOf listview_items_count)), [B]Integer[/B])
        Else
            [B]Return [/B]Me.listview.Items.Count
        End If
    End Function
 
Back
Top