Hi,
I have a custom type defined as below and then I have a map made of several of such objects.
Now I would need to "clone" one of these elements and create one which is basically like one of them with only one field changed.
If I do this the newElem is actually inserted and all the fields are ok but the field3 gets changed in MyElem too.
I would like to avoid to manually set each Field in the newElem obj (in reality they are more than 30...). Is there a smart way to do that?
thanks
I have a custom type defined as below and then I have a map made of several of such objects.
B4X:
Type MyObj (Field1 As String, Field2 as string,Field3 as int) 'etc...'
dim MyMap as map
dim Elem as MyObj
....
MyMap.initialize
Elem.Inizialize
Elem.Field1 ="something"
Elem.Field2 ="something else"
....
MyMap.put(MyElemKey,Elem)
....
Now I would need to "clone" one of these elements and create one which is basically like one of them with only one field changed.
B4X:
dim MyElem as MyObj, NewElem as MyObj
MyElem.initialize
MyElem = MyMap.GetValueAt(index) 'index = one of the maps elements'
NewElem.Initialize
NewElem = MyElem
NewElem.Field3 ="something different" 'in this way new elem should have all fields equal to elem(index) but one field which is different
'now I add the NewElem to the map
MyMap.Put(NewKey,NewElem)
If I do this the newElem is actually inserted and all the fields are ok but the field3 gets changed in MyElem too.
I would like to avoid to manually set each Field in the newElem obj (in reality they are more than 30...). Is there a smart way to do that?
thanks
Last edited: