Appending a value to an array within a dictionary

I have a Xojo.Core.Dictionary where the Keys are the names of tags and the Values are arrays of a custom class (called Node).

I’m struggling to work out how to append a new Node class to one of the Node arrays. The following gives the error Type Auto has no member named "Append":

If dict.HasKey(tagName) Then ' The Dictionary has an array entry for this tag name so lets just append to it dict.Value(tagName).Append(theNode) Else ' This is the first time we have encountered this tag so create a new Node array from this Node dict.Value(tagName) = Array(theNode) end if

Is it possible to tell the compiler that dict.Value is an array of Node objects? I can’t figure out how to cast it.

Use a temporary rather than trying to chain the append on

If dict.HasKey(tagName) Then ' The Dictionary has an array entry for this tag name so lets just append to it dim tmp() as Node = dict.Value(tagName) tmp.Append(theNode) dict.Value(tagName) = tmp Else ' This is the first time we have encountered this tag so create a new Node array from this Node dict.Value(tagName) = Array(theNode) end if

That seems to cause a hard crash of the debugger. My code runs fine but if I put a break point after I’m done building the Dictionary and inspect the Dictionary in the debugger it goes wrong. Specifically, if I inspect a Dictionary key whose value is an array of only one item, everything is OK. However, if I inspect the value of a key where the array in the Dictionary value has more than one item, the app crashes immediately and takes me back to the IDE. The code seems to work in that the correct number of items are present in the array in the Dictionary values but as soon as I try to inspect them, it crashes.

Interestingly, if I use your code but instead of having an array of a custom class I use a built-in type (say Text) it works fine. I was wondering if it was some sort of circular reference but even if I create just a dummy new instance of a custom class and assign it to an array then the crash happens again.

yeah I’m seeing that in the debugger as well when trying to dig in by inspecting the dictionary in the debugger

however if you inspect the temporary things all seem to be working as expected

<https://xojo.com/issue/48625>

Thanks. Just favourited the case. Might have to find a workaround to hold a collection of Nodes. Maybe I’ll try an in-memory SQLite DB or something.

Actually, it does just seem to be limited to the debugger. In code, I am able to access the custom classes via the temporary as you mentioned. Phew!