Click here to Skip to main content
16,020,741 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I keep getting the following error:
""Delegate 'system.windows.forms.methodinvoker'
requires an 'AddressOf'expression or
lambda expression as the only argument to its constructor.""

Please Help Me.
-----------my code------------------
VB
Public Sub search()
        Try

            cmdoledb.CommandText = "SELECT NAME FROM table1 WHERE ID=" & CInt(txtid.Text)
            cmdoledb.CommandType = CommandType.Text
            cmdoledb.Connection = cnnoledb
            Dim rdroledb As OleDbDataReader = cmdoledb.ExecuteReader
            While rdroledb.Read = True
                updatetext(rdroledb.Item(0).ToString)
                Thread.Sleep(2000)
                tictac()
            End While
            t1.Abort()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        cmdoledb.Dispose()
    End Sub
    Private Sub updatetext(ByVal text)
        If Me.InvokeRequired Then
            Me.Invoke(Me.Invoke(New MethodInvoker(AddressOf updatetext, text)))
        Else
            txtnam.Text &= text
        End If
    End Sub
Posted
Comments
Christian Graus 19-May-10 16:15pm    
Reason for my vote of 1
Not for the dumb question, but for asking it again, after I answered it.
William Winner 19-May-10 16:28pm    
Reason for my vote of 1
inability to understand a simple error message

Do you not understand the English in the error? Is that the problem?

MethodInvoker does not have an overload that allows for multiple parameters. The error tells you everything:
ehsan6000 wrote:
Delegate 'system.windows.forms.methodinvoker'
requires an 'AddressOf'expression or
lambda expression as the only argument to its constructor.


MethodInvoker only takes one argument. If you want to pass a parameter, you do that in the Invoke...as in:
VB
Me.Invoke(New MethodInvoker(AddressOf updatetext),New Object(){text})


and Christian is right...what's up with Me.Invoke twice? You need to try to understand what you're writing before doing it.
 
Share this answer
 
Your basic issue is a combination of cluelessness and illiteracy. I assume, despite you not telling us, that this line is the error:


ehsan6000 wrote:
Me.Invoke(Me.Invoke(New MethodInvoker(AddressOf updatetext, text)))


Why are you calling me.invoke twice ? Is it because

a - this is actually right, me.invoke returns the same thing as AddressOf

b - you get an error after copying code blind off the web, so ask here because you can't use google, can't read, and have no idea what you're doing ( and therefore cannot diagnose the problem ) ?

Oh, your code is still terrible - SQL in the presentation layer, the assumption that a textbox contains an int, etc. What happens if someone types text in to that textbox ?
 
Share this answer
 
v2
Comments
Dalek Dave 20-May-10 17:35pm    
It almost looks like it ought to run, but yeah, a bit ugly and hard to follow logically with the invoking.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900