< Continued from page 1
We've seen that delegates really hold the address of procedures. In fact, they can hold more than one address and when a delegate contains more than one address, it's called a multicast delegate. The list of addresses is called an invocation list. In the case of an event that calls a multicast delegate, all of the addresses in the invocation list get called.
To make that work, VB.NET provides the Combine function.
Just assign both addresses to the same delegate and combine them:
Dim myDel1 As MyDelegate = _
New MyDelegate(AddressOf SayHelloInEnglish)
Dim myDel2 As MyDelegate = _
New MyDelegate(AddressOf SayHelloInDeutch)
Dim myDelBoth As MyDelegate = _
[Delegate].Combine(myDel1, myDel2)myDelBoth.Invoke()
(Note: The delegate subroutines would also have to be modified with something like ...
lblHello.Text &= vbCrLf & "Guten Tag"
... to avoid replacing the text in the label.
previous post