パーサーにこのコードがあり、テキストを Form1 に渡して、ラベルなどを更新できるようにします。(私の構造は次のとおりです: Form1 -> Engine -> Parser) 2 つの文字列を渡す必要がある場合もあれば、それ以上の場合もあります。
Public Class Parser
Public Event NewInfo(<[ParamArray]()> Byval strArray() as String)
Public Sub SomeParser(ByVal m As Match)
Dim strArray() As String = {"Word1", "Word2"}
RaiseEvent NewInfo(strArray)
End Sub
End Class
次に、この別のクラスがあります。Array を Engine に渡し、その後 Form1 に渡します。
Public Class Engine
Private parent as Form1
Private WithEvents Parser As New Parser
Private Sub New(ByRef parent as Form1)
Me.parent = parent
EndSub
Private Sub ChangeLabel(ByVal str() As String) Handles Parser.NewInfo
parent.UpdateTextLabel(str)
End Sub
そして、私はForm1にこれを持っています:
Public Class Form1
Private WithEvents Engine as New Engine(Me)
Public Delegate Sub UpdateTextLabelDelegate(<[ParamArray]()> ByVal text() As String)
Public Sub UpdateTextLabel(ByVal ParamArray str() As String)
If Me.InvokeRequired Then
Me.Invoke(New UpdateTextLabelDelegate(AddressOf UpdateTextLabel), str())
Else
(Do stuff here)
End Sub
End Class
コードは Me.invoke(New UpdateTextLabelDelegate).... 行で停止します。例外は次のようなものです: System.Reflection.TargetParameterCountException したがって、パラメーターの量が間違っているようなものです..これを正しく行う方法は?
誰かが説明して、これを行う方法を理解できれば、とてもうれしいです。