Hi
I’m playing now since almost 2 years with xojo, doing some prototypes on desktop and web. Now I’m working on the first realworld desktop app. I’m hanging with classes as value in a dictionary.
I have reading this blog Xojo Blogpost and followed in this forum post jeff’s car example.
Context:
I’m writing a software to manage a sportsevent. The data of each event will be stored in a json-file. When the software starts, the user choose a data-file (json) for the actual event. In the data-file will be information about the event (date, name, judge and so on). But also arrays of data like categories, classes (beginners, pro ..), participants, results. The datas should be stored globaly in dictionaries, so that all windows/methodes can worked with them.
I can load the eventinformations from the json to a dictionary and load it in a window into a ValueListBox. This is handled as key-value list. It works.
But there are the arrays in the json.
Problem:
I had took jeffs example and changed.So I created a class for Event Classes call “EventClass“. This class has properties like “class_id“, “class_name”. Then I created a property “EventClassDic“ from type dictionary. And I create a instance of “EventClassDic“ by adding “EventClassDic = New Dictionary“ in the opening Handler of the app.
When the user opens the datafile, all classes should be loaded to the dictionary. The class_id will be the key of the dictionary, the value should be a new “EventClass” Object. The properties of the “EventClass“-Object gets the data (class_id, class_name) from the json-object. and then the Class will be stored as value in the dictionary.
Var classesArr As JSONItem = root.Value("classes")
For i As Integer = 0 To classesArr.Count - 1
Var cObj As JSONItem = classesArr.Child(i)
var cClass as Globals.EventClass
cClass = new Globals.EventClass
cClass.class_id = cObj.Value("class_id")
cClass.class_name =cObj.Value("class_name")
EventClassesDic.value(cObj.Value("class_id")) = cClass
Next
In a other window I would like to show the data of the dictionary.value (= class “EventClass”)
ValuesListBox.removeAllRows
For Each entry As DictionaryEntry In EventClassesDic
system.debugLog("Class ID im Dic " + entry.key)
If Not EventClassesDic.HasKey(entry.key) Then
system.debugLog("Nicht gefunden '" + entry.key )
else
var oClass As Globals.EventClass = EventClassesDic.Value(entry.key)
system.debugLog("Id im Objekt " + oClass.class_id)
ValuesListBox.AddRow oClass.class_name
ValuesListBox.RowTagAt(ValuesListBox.lastAddedRowIndex) = oClass.class_id
End If
But as result/output I get a list of the same eventclass (“Plausch“).
You see in the code that I have output some log: so i see the dictionary is filled correctly with the key (=class_id). But not correct with the value (class “EventClass“).
It looks that I have a missing a thing in the code to create a new class for every entry.
Can anyone help?
Daniel








