Sometime when you’re debugging your application you run into a situation where you get funky behaviour.
You might do something like Javier mentioned in his recent blog post on Xojo’s blog :
Dim ASource() As Integer = Array(1,2,3,4,5,6,7,8)
Dim ATarget() As Integer
ATarget = ASource
And, as he noted, you cant figure out why when you change one array you also appear to alter the other. This can also happen with other reference types as I noted in other posts.
For instance I’ve seen
Dim d As New Date
Dim d1 As date
d1 = d
d1.month = 2
and then the question of “why did d change?” arises
Again this has been covered before and it has to do with both arrays and dates, as well as many other type, being reference types.
One way to see that in fact these are the same object is not well documented in the Xojo documentation. Its buried in the Debugging pane of the preferences – Show Object IDs in variable lists.
Once you enable this setting what you see in the debugger pane makes it much easier to see when you have two references to the same object.
When viewing the following code
Dim ASource() As Integer = Array(1,2,3,4,5,6,7,8)
Dim ATarget() As Integer
ATarget = ASource
You can clearly see that ATarget and ASource have the same objectID. In Xojo’s runtime this means they are the same object – objectsID’s are unique to every instance and the only way you get two objectID’s that are the same is when two references refer to the same object.
I’d recommend always turning this setting on when debugging.