Bug? List bug adding Map object

wizard699

Active Member
Licensed User
Longtime User
Erel,
there is a bug in method Add of a List.... or I'm crazy.

This is an example .... m is a Map object, filled with some record from a table.
l_subcat is a List object

For Row = 0 To RowNumber - 1
Cursor1.Position = Row 'set the Cursor to each row

m.Put("id_cat_subcat", Cursor1.GetString("cat_subcat.id_cat_subcat") )
m.Put("desc_subcategoria", Cursor1.GetString("subcategorie.desc_subcategoria") )

l_subcat.Add(m)

Next

m change on every for cycle.
But ... the method Add seems to substitute (at every execution) all the item yet inserted ... with the last map object added. Is it possible?

I've noticed the problem adding a map object. It's a bug? Or I'm wrong something?

At the end of the Fro cycle, all the item in the List object are the same ...
 

DonManfred

Expert
Licensed User
Longtime User
Cursor1.Position = Row 'set the Cursor to each row

m.Put("id_cat_subcat", Cursor1.GetString("cat_subcat.id_cat_subcat") )
m.Put("desc_subcategoria", Cursor1.GetString("subcategorie.desc_subcategoria") )

l_subcat.Add(m)

add a DIM for each iteration for the map....
B4X:
Cursor1.Position = Row 'set the Cursor to each row
dim m as map 
m.initialze
m.Put("id_cat_subcat", Cursor1.GetString("cat_subcat.id_cat_subcat") )
m.Put("desc_subcategoria", Cursor1.GetString("subcategorie.desc_subcategoria") )

l_subcat.Add(m)
 

DonManfred

Expert
Licensed User
Longtime User
At the end of the Fro cycle, all the item in the List object are the same ...
It is because you dimmed it ONCE and always adding the same object instead of adding a new one each time. In fact you are adding references to the same object. All references of this object will have the same content.
 
Top