J
JB
Hi All,
I've discovered a strange behaviour with Object parameters passed
ByVal via remoting and I'm wondering if anybody could shed some light
on this.
In a non remoting function call, when a object (as opposed to a value
type like Integer, Boolean, etc) is passed as a ByVal parameter, it's
content can be modified. This is somehow "strange", but I've lived
with that so far.
Now when the exact same function is called via remoting (i.e. the
parameter will be serialized for the call) the content of the object
is NOT modified. It looks a bit inconsistent to me and I'd like to
know if I'm missing something. Or is there a way I can change this
without having to use ByRef.
Code sample below.
Thanks
JB
<Serializable()> _
Class CTest
Public Value As String
End Class
Public Sub ChangeValueByVal(ByVal Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByVal)"
End Sub
Public Sub ChangeValueByRef(ByRef Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByRef)"
End Sub
Dim Test As New CTest
'In Non Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called locally)
'====================================================================
Test.Value = "Initial Value"
ChangeValueByVal(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByVal)"
'<== OK
ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK
'So Far so Good...
'Now In a Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called remotely)
'=======================================================================
Test.Value = "Initial Value"
ChangeValueByVal(Test)
'Upon exit Test contains "Initial Value" '<== Inconsistent, why is
that !!!!
ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK
I've discovered a strange behaviour with Object parameters passed
ByVal via remoting and I'm wondering if anybody could shed some light
on this.
In a non remoting function call, when a object (as opposed to a value
type like Integer, Boolean, etc) is passed as a ByVal parameter, it's
content can be modified. This is somehow "strange", but I've lived
with that so far.
Now when the exact same function is called via remoting (i.e. the
parameter will be serialized for the call) the content of the object
is NOT modified. It looks a bit inconsistent to me and I'd like to
know if I'm missing something. Or is there a way I can change this
without having to use ByRef.
Code sample below.
Thanks
JB
<Serializable()> _
Class CTest
Public Value As String
End Class
Public Sub ChangeValueByVal(ByVal Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByVal)"
End Sub
Public Sub ChangeValueByRef(ByRef Test As CTest)
Test.Value = "Value Has been changed by the Sub (ByRef)"
End Sub
Dim Test As New CTest
'In Non Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called locally)
'====================================================================
Test.Value = "Initial Value"
ChangeValueByVal(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByVal)"
'<== OK
ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK
'So Far so Good...
'Now In a Remoting Environement (i.e. ChangeValueByVal and
ChangeValueByRef called remotely)
'=======================================================================
Test.Value = "Initial Value"
ChangeValueByVal(Test)
'Upon exit Test contains "Initial Value" '<== Inconsistent, why is
that !!!!
ChangeValueByRef(Test)
'Upon exit Test contains "Value Has been changed by the Sub (ByRef)"
'<== OK