Android Question Creating and executing dynamic object assignments at runtime ?

Aegis

Member
Hello
Basically, I've been wondering if part of the left side of an assignment can be made parametric.
To explain:

Lets say i have a json of properties
JSON:
{
        "widht": "100%",
        "color": -1454129,
        "txtcolor": -12864927,
        "xoffset": 0
    .........
},

I get the json from an mqtt server, and assign those properties to an object.
Now, what if i dont know beforehand which and how many the managed properties will be? Maybe just these 4, maybe 100 or n
Is it possible to write code like this?

B4X:
MyObject.interface.X = Y

Of course assuming the json doesnt contain properties unsupported by Myobject.interface.
I know something similar can be done in .net, no clue about b4x thou


Thanks alot for your time
 

Aegis

Member
Thanks for the reply, but if i understood correctly, isnt that just skipping the json middleman?

1-Subscribe to the topic
2-Wait for the json string (or serialized map)
2-Parse that string into a map (or un-serialize the map)
3-Pass such map to a sub that creates views based on the attributes, to be added in a xcustomlistview

Es. for color:
B4X:
Dim p As B4XView = xui.CreatePanel("")
Dim panelcolor As Int = m.Getdefault("color",Colors.Transparent)
p.color=panelcolor
......
....Rinse and repeat for all the properties


What im looking for , is something like this:
B4X:
Dim p As B4XView = xui.CreatePanel("")
For Each k As String In map.Keys
    p.<k> = map.get(k)  
Next

...iterating on all the map, setting properties i didnt even consider when compiling the code
 
Upvote 0
Top