Android Question Map of own type

wroyw

Member
Licensed User
Hi,

I'll make a map of my own type :

B4X:
Type TMyType ( _
  v1 As Int , _
  v2 As Int )
Dim myMap As Map
myMap.Initialize
Dim myType as TMyType
myType.v1 = 1
myType.v2 = 2
mYmap.put(0,myType)
myType.v1 = 3
myType.v2 = 4
mYmap.Put(1,myType)

It works, but in both entries now are the values 3 and 4.
I think the "Put" method only insert a pointer in the map, but why it works with other standard values like string Int ...

Thanks in advanced
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Type TMyType ( _
  v1 As Int , _
  v2 As Int )
Dim myMap As Map
myMap.Initialize
Dim myType as TMyType
myType.v1 = 1
myType.v2 = 2
mYmap.put(0,myType)
Dim myType as TMyType ' Dim a NEW Instance each time....
myType.v1 = 3
myType.v2 = 4
mYmap.Put(1,myType)
 
Upvote 0
Top