E
eBob.com
If I have a structure and I pass it ByRef to a Subroutine via a Delegate,
any changes to the structure are not seen by the caller. This sure seems
unfortunate to me and I would welcome any explanation of why this is
reasonable behavior. In any event I think that the Delegate documentation
should point this out in bold face type. The following code illustrates the
problem:
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
Delegate Sub delegTestSub(ByRef si As SiteRunOpts)
Structure SiteRunOpts
Public set_by_Load_code As String
Public set_by_TestSub_code As String
End Structure
Public Shared Sites(0) As SiteRunOpts
Public onesite As SiteRunOpts
#Region " Windows Form Designer generated code "
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
onesite = Sites(0)
onesite.set_by_Load_code = "SET"
Dim CallDaSub As delegTestSub = New delegTestSub(AddressOf testsub)
Me.Invoke(CallDaSub, New Object() {onesite})
'
''> onesite.set_by_TestSub is Nothing here !?!?!?!
'
End Sub
Private Sub testsub(ByRef site As SiteRunOpts)
site.set_by_TestSub_code = "SET"
End Sub
End Class
(You have to use the debugger to see what I am saying. Also, sorry if this
gets posted twice; I am having a problem with OE.)
Bob
any changes to the structure are not seen by the caller. This sure seems
unfortunate to me and I would welcome any explanation of why this is
reasonable behavior. In any event I think that the Delegate documentation
should point this out in bold face type. The following code illustrates the
problem:
Option Explicit On
Option Strict On
Public Class Form1
Inherits System.Windows.Forms.Form
Delegate Sub delegTestSub(ByRef si As SiteRunOpts)
Structure SiteRunOpts
Public set_by_Load_code As String
Public set_by_TestSub_code As String
End Structure
Public Shared Sites(0) As SiteRunOpts
Public onesite As SiteRunOpts
#Region " Windows Form Designer generated code "
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
onesite = Sites(0)
onesite.set_by_Load_code = "SET"
Dim CallDaSub As delegTestSub = New delegTestSub(AddressOf testsub)
Me.Invoke(CallDaSub, New Object() {onesite})
'
''> onesite.set_by_TestSub is Nothing here !?!?!?!
'
End Sub
Private Sub testsub(ByRef site As SiteRunOpts)
site.set_by_TestSub_code = "SET"
End Sub
End Class
(You have to use the debugger to see what I am saying. Also, sorry if this
gets posted twice; I am having a problem with OE.)
Bob