Forum Discussion

btpoole's avatar
btpoole
Channel Surfer
9 years ago

Field "Created" -Well Maybe Not

I have seen others post about this problem and have run into it also but with help was able to work thru, except now. I am using the following code to create a child of a contentnode, add a field, assign a value. When executed, the code says the field is created but really it's not.

                         content = CreateObject("roSGNode", "ContentNode")
                          dataItem = content.CreateChild("ContentNode")
                          dataItem.addfield("zip", "string", false)
                          ?"HAS FIELD "dataItem.hasfield("zip")
                         dataItem.zip=zipc
                          m.top.content=content
                          ?content
                         ?dataitem.zip

Have also tried
                                                   content = CreateObject("roSGNode", "ContentNode")
                                                  dataItem = content.CreateChild("ContentNode")
                                                  dataItem.addfields({"zip" : zipc})
                                                 ?"HAS FIELD "dataItem.hasfield("zip")
                                                 ?content
                                                  ?dataitem.zip

I basically coped the second code from another part of my app that works fine. The print of dataitem.zip displays correctly but the print of the content doesn't show the field as being added. What else could be done?

2 Replies

  • You are looking in the wrong place - print DataItem and you will see it.

    That printing DataItem's parent Content does not print its children nodes is unsurprising. It only prints the fields. But ask for the 1st child and you'll see it:
    Brightscript Debugger> ? content.getChild(0)   ' = dataItem `
    <Component: roSGNode> =
    {
       metadata: <Component: roContentMetadata>
       change: <Component: roAssociativeArray>
       focusable: false
       focusedChild: <Component: roInvalid>
       id: ""
       zip: "zipC"
    }