But, the end result is that the vChar property will be changed in the
original object.
Object references are just that. They only point to the actual object. If
you pass an object reference ByRef it still is just a pointer to the object.
The only difference is that the original object reference will change if you
assign the passed reference. For example:
Private sub Foo
Dim Bar as New Bar
SetFoo(Bar)
'When you come back here Bar now points to the new object created in SetFoo
End Sub
Private Sub SetFoo(byRef Bar as Bar)
Bar.Foo = "New Value" ' Changes the property in the original object
created in Foo
Bar = New Bar ' Creates a new object
End Sub
If parameter Bar in the SetFoo sub was defined as ByVal then the original
Bar variable in Sub Foo will not change and still point to the original
object.
NOTE: This is horrible programming but does show the difference on object
references passed as ByRef or ByVal.
"Herfried K. Wagner [MVP]" wrote:
<ar*******@hotmail.com> schrieb: Class HumpaLumpa
Public Sub CoolSub(ByRef pCar As Car)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar.WindowDown=True 'did the original object get changed or
just a copy of it?
The original object because 'Car' is a class and thus a reference type.
This is a second example:
Class HumpaLumpa
Public Sub CoolSub(ByRef pCar As Integer)
Me.vCar=pCar
End Sub
.
.
.
Me.vCar=22 'did the original variable get changed or
just a copy of it?
Just a copy of it. The assignment 'Me.vCar = pCar' will create a copy of
'pCar''s value and assign it to 'vCar'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>