L LowHZ New Member Licensed User Dec 13, 2016 #1 Hi all, I got a problem with lists in B4A. I have to add items to a list, The list must be populated with a custom class, the class variables get populated by an API CALL that answer with a XML To parse the xml i'm using XmlSax and inside this event: Code: Copy Sub parser1_EndElement (Uri As String, Name As String, Text As StringBuilder) select case Name case "test" myclass.name = Text end sub The class that must be populated is placed in the Globals Variables declarations So in the process I populate the class that will be added to the list using the Parser. Everytime it make a new call the class must be reset so i put in the code myClass.Initialize The problem is, everytime i make a new API CALL it gets the new response with different values but when i try to add the class to the list, it adds everytime the class but with the same values of the previous item so i get only clones of the first item in the list. How can i solve it?
Hi all, I got a problem with lists in B4A. I have to add items to a list, The list must be populated with a custom class, the class variables get populated by an API CALL that answer with a XML To parse the xml i'm using XmlSax and inside this event: Code: Copy Sub parser1_EndElement (Uri As String, Name As String, Text As StringBuilder) select case Name case "test" myclass.name = Text end sub The class that must be populated is placed in the Globals Variables declarations So in the process I populate the class that will be added to the list using the Parser. Everytime it make a new call the class must be reset so i put in the code myClass.Initialize The problem is, everytime i make a new API CALL it gets the new response with different values but when i try to add the class to the list, it adds everytime the class but with the same values of the previous item so i get only clones of the first item in the list. How can i solve it?
Erel B4X founder Staff member Licensed User Longtime User Dec 13, 2016 #2 Add Dim myClass As YourClass before you initialize it. Upvote 0
L LowHZ New Member Licensed User Dec 13, 2016 #3 Already done It won't works Code: Copy Dim myArticoloA As Articolo myArticoloA.Initialize myArticoloA.CodArt = myArticolo.CodArt myArticoloA.IdArticolo = myArticolo.IdArticolo myArticoloA.IdIVA = myArticolo.IdIVA myArticoloA.IdMagaz = myArticolo.IdMagaz myArticoloA.IdRipiano = myArticolo.IdRipiano myArticoloA.IdScaff = myArticolo.IdScaff myArticoloA.IdSett = myArticolo.IdSett myArticoloA.Modello = myArticolo.Modello myArticoloA.nCosto = myArticolo.nCosto myArticoloA.nPrezzo2 = myArticolo.nPrezzo2 myArticoloA.PrezzoIVA = myArticolo.PrezzoIVA myArticoloA.Qty = myArticolo.Qty myArticoloA.sMarca = myArticolo.sMarca myArticoloA.UM = myArticolo.UM myArticoloA.Articolo = myArticolo.Articolo ListaArticoli.Add(myArticoloA) Upvote 0
Already done It won't works Code: Copy Dim myArticoloA As Articolo myArticoloA.Initialize myArticoloA.CodArt = myArticolo.CodArt myArticoloA.IdArticolo = myArticolo.IdArticolo myArticoloA.IdIVA = myArticolo.IdIVA myArticoloA.IdMagaz = myArticolo.IdMagaz myArticoloA.IdRipiano = myArticolo.IdRipiano myArticoloA.IdScaff = myArticolo.IdScaff myArticoloA.IdSett = myArticolo.IdSett myArticoloA.Modello = myArticolo.Modello myArticoloA.nCosto = myArticolo.nCosto myArticoloA.nPrezzo2 = myArticolo.nPrezzo2 myArticoloA.PrezzoIVA = myArticolo.PrezzoIVA myArticoloA.Qty = myArticolo.Qty myArticoloA.sMarca = myArticolo.sMarca myArticoloA.UM = myArticolo.UM myArticoloA.Articolo = myArticolo.Articolo ListaArticoli.Add(myArticoloA)
Erel B4X founder Staff member Licensed User Longtime User Dec 13, 2016 #4 The problem is somewhere else. Hard to say where without seeing your code. Upvote 0
L LowHZ New Member Licensed User Dec 14, 2016 #5 It looks like the class that i add to the list is binded to the list for example myarticolo.id= 10 myarticolo.title="asdsda" myarticolo.etc etc... Code: Copy ListaArticoli.Add(myArticolo) myArticolo.Initialize if i run this code in the list i'll get the list something like this: List.get(0) = [myarticolo.id=null] [myarticolo.title=null] [etc..=null] instead of this it should show this: List.get(0) = [myarticolo.id=10] [myarticolo.title="asdsda"] [etc..="values...etc"] Upvote 0
It looks like the class that i add to the list is binded to the list for example myarticolo.id= 10 myarticolo.title="asdsda" myarticolo.etc etc... Code: Copy ListaArticoli.Add(myArticolo) myArticolo.Initialize if i run this code in the list i'll get the list something like this: List.get(0) = [myarticolo.id=null] [myarticolo.title=null] [etc..=null] instead of this it should show this: List.get(0) = [myarticolo.id=10] [myarticolo.title="asdsda"] [etc..="values...etc"]
Erel B4X founder Staff member Licensed User Longtime User Dec 14, 2016 #6 As I previously wrote you should dim your class before you initialize it. Otherwise you are using the same instance all the time. Code: Copy List.Add(...) Dim my As Something my.Initialize Upvote 0
As I previously wrote you should dim your class before you initialize it. Otherwise you are using the same instance all the time. Code: Copy List.Add(...) Dim my As Something my.Initialize