I’m very new to Xojo (4 days) and also to the programming world (I’ve previous little knowledge of C, C++, ObjC and lately Swift).
I’m trying to understand programming by myself and I’ve already accomplish something big for a real newbie like me.
I’ve developed a few desktop and iOS apps and an easy game based on colors and I would like to save infos of the game in an array of dictionaries and show them in a listbox, like a hall of fame
To understand better, I’ve started from scratch in a new project with three fields and two buttons: Add item and Open Table
I’ve created a module with a global array and a dictionary. I’ve filled the text field and when I’ve pressed the button has assigned the value of the text fields to the dictionary.
After that has added the dictionary to the array.
[code] myDictionary.Value(“nome”)= NomeField.Text
Another button opens a window with a listbox. On the listbox open event there’s a for each loop to add a row for every single key.
for each element as Dictionary in myArray
Listbox1.addRow(element.Value("nome").stringValue, element.Value("cognome").stringValue, element.Value("et").stringValue)
When I’ve run the app and I’ve started to add values in the text fields and to the array I’ve tried to press the button to fill the list and all the rows were the same.
I think that is something relate to object-referencing. Every instance of the dictionaries stored in the array are pointing to the same location in memory hence the list is all the last entry.
While I was debugging I saw that, when the second append function takes place, the first index changes value as well.
I’ve read a lot before asking for help but I’m really puzzled, please give me a hint to get out of the pit!!
Thanks in advance
P.S: I’ve also added
myDictionary = new Dictionary to the App Open event