签名与委托不兼容 [英] Signature not compatible with delegate
本文介绍了签名与委托不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下错误:
I am getting the following error:
"Method ''Private Sub updatetext(text As Object)'' dose Not have a signature compatible with delegate Delegate Sub MethodInvoker()"
请帮帮我.
-----------我的代码------------------
Please Help Me.
-----------my code------------------
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(New MethodInvoker(AddressOf updatetext),New Object(){text})
Else
txtnam.Text &= text
End If
End Sub
推荐答案
MethodInvoker是不带参数的通用委托(签名).如果要将参数传递给委托,则需要创建自己的Invoker委托,如下所示:
The MethodInvoker is a generic Delegate with no arguments (signature). If you want to pass arguments to a delegate then you need to create your own Invoker Delegate Like this :
Private Delegate Sub UpdateTextInvoker(ByVal MyText As String)'Create your own Invoker Delegate
Private Sub UpdateText(ByVal MyText As String)
If Me.InvokeRequired Then
Me.Invoke(New UpdateTextInvoker(AddressOf UpdateText), New String() {MyText})'Call your custom invoker
Else
txtName.Text = MyText
End If
End Sub
希望这会有所帮助
快乐编码
Hope this helps
Happy Coding
这篇关于签名与委托不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文