Bug? List bug adding Map object

Discussion in 'Bugs & wishlist' started by wizard699, Jun 27, 2015.

  1. wizard699

    wizard699 Member Licensed 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 ...
     
  2. wizard699

    wizard699 Member Licensed User

    I'm using B4a 5.02
     
  3. DonManfred

    DonManfred Expert Licensed User

    add a DIM for each iteration for the map....
    Code:
    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)
     
  4. DonManfred

    DonManfred Expert Licensed User

    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.
     
    RandomCoder likes this.
  5. DonManfred

    DonManfred Expert Licensed User

    Ohh, i forgot: It´s not a BUG, it´s a feature
     
  6. wizard699

    wizard699 Member Licensed User

    It's true!!!!! I'm stupid. Thanks DonManfred
     
Loading...