problem using delegates with Option Strict On

  • Thread starter Thread starter Rich
  • Start date Start date
R

Rich

Hello,

The following Delegates example works with Option Strict
Off, but if I change it to Option Strict On then VB.Net
complains about the line

dgY = System.Delegate.Combine(dgI, dgA)

Is there a way to use the Combine method of Delegates in
VB.Net with Option Strict On?
----------------------------------------------------------
Example:

Option Strict Off
Option Explicit On
Option Compare Binary

Public Class Form1
Inherits System.Windows.Forms.Form

+Windows Form Designer Generated Code

Delegate Sub dg()
Dim dgI, dgA, dgY As dg

Private Sub Form1_Load(...) Handles MyBase.Load
dgI = AddressOf Hi
dgA = AddressOf Bye
dgY = System.Delegate.Combine(dgI, dgA)
End Sub

Sub Hi()
MsgBox "Hi"
End Sub

Sub Bye()
MsgBox "Bye"
End Sub

Private Sub Button1_Click(...) Handles Button1.Click
dgI()
dgA()
dgY()
End Sub
End Class
 
Rich said:
The following Delegates example works with Option Strict
Off, but if I change it to Option Strict On then VB.Net
complains about the line

dgY = System.Delegate.Combine(dgI, dgA)

Replace the line above with this line:

\\\
dgY = DirectCast(System.Delegate.Combine(dgI, dgA), dg)
///
 
dgY = System.Delegate.Combine(dgI, dgA)

dgY = CType(System.Delegate.Combine(dgI, dgA), dg)



Mattias
 

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

Similar Threads


Back
Top