I'm looking at example 3-1 on page 40 of the book "Developing Microsoft ASP.NET Server Controls and Components" by Microsoft Press. UNFORTUNATELY, the example is ONLY in C#. The authors of the book said they would point out differences between C# and VB.NET,
but this example has not such thing. I've tried typing in something that I think is the VB.NET equivalent, but it does not compile. Here's the code (The error happens on the call to objPrinter.PCB(10), etc.) Module Module1 Sub main() Dim objdriver As New Driver
objdriver.Main() End Sub Public Delegate Sub PrintCallback(ByVal number As Integer) Public Class Printer Private _print As PrintCallBack Public Property PCB() As PrintCallBack Get Return _print End Get Set(ByVal Value As PrintCallBack) _print = Value End Set
End Property End Class Public Class Driver Private Sub PrintInteger(ByVal number As Integer) Console.WriteLine("From PrintInteger: The Number is " & number) End Sub Sub Main() Dim objDriver As New Driver Dim objPrinter As New Printer objPrinter.PCB = New PrintCallback(AddressOf
objDriver.PrintInteger) objPrinter.PCB(10) 'ERROR HERE objPrinter.PCB(100) 'ERROR HERE End Sub End Class End Module Any help would be greatly appreciated. TIA,
Change the lines objPrinter.PCB(10) objPrinter.PCB(100) to objPrinter.PCB.Invoke(10) objPrinter.PCB.Invoke(100) Interesting that VB is more picky about this than C# (traditionally, VB made it easier to code over C-style languages). I wonder why Microsoft changed
that aspect of VB.... Cheers,
ojm37
Contributor
2248 Points
832 Posts
Not understanding Delegates
Sep 03, 2003 10:39 PM|LINK
ojm37
Contributor
2248 Points
832 Posts
Re: Not understanding Delegates
Sep 03, 2003 11:43 PM|LINK