Help with a delegate

J

John Wright

I have a delegate that I have defined as follows:

Public Delegate Sub myDelegate (ByVal txtBox as TextBox, byval Port as
System.IO.Ports.SerialPort)

I have a sub with the same definition. When I try to call the delegate with
an invoke I can't figure out the syntax to call it with both parameters. I
have tried:

TextBox1.Invoke(New myDelegate(AddressOf UPdateTextBox()), New Object()
{TextBox1,SerialTare})



Thinking it would work, but I can't get the signature right. I keep getting
the compiler error Argument not specified for parameter Port.

How can I write the invoke method with the correct signature to pass in both
parameters?



John
 
S

Stephany Young

TextBox1.Invoke(New myDelegate(AddressOf UPdateTextBox), TextBox1,
SerialTare)

There are 2 separate parameters, not an array.
 
J

Jack Jackson

It shouldn't matter which way it is done, with separate parameters or
an array. The second argument to Control.Invoke is "ParamArray args()
As Object" which should accept either an array or separate parameters.

I tried the code below and it compiled OK for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top