How to give a software-instance of serial a DataAvailable event handler?

Greetings -

I have a class Channel that has a property MySerial of class Serial. I make an “effective” array of Channels. How do I assign a DataAvailable event handler to MySerial?

Thanks
Jim

James Wagner
Oregon Research Electronics

Check out AddHandler.

or make a subclass.

Thanks!

Got a problem, now, trying to use AddHandler

TheChannels(Idx).TheSerial = new Serial
AddHandler TheChannels(Idx).TheSerial.DataAvailable, AddressOf TheChannels(Idx).MySerialDataAvailable

TheChannels is an “array” of class Channel. The code, above, is where a new member is added to the array. That part has been working. Channel has a property TheSerial of type Serial. MySerialDataAvailable is a method of class Channel. I get an error message:

Type mismatch error. Expected delegate Delegate(Serial) but got delegate Delegate().

I have no clue about the meaning of this or what is the right way is to proceed. Help would be appreciated. I also do not understand how one would implement Christian’s suggestion of a subclass, above.

Uggg, just found it. The function that is going to handle the DataAvailable events did not have an argument (TheSerial as serial). That fixes it. Sorry for the noise.

Many thanks,
Jim

James Wagner
Oregon Research Electronics

James, don’t forget to call RemoveHandler if you’re destroying these objects periodically. Otherwise these objects will leak.

Thanks Greg - I had, indeed, forgotten to do that. Users CAN remove channels from the channel list.

Jim