Shared objects and collections not allowing more of two levels

While I was trying to write some code to clone standard objects and collections to shared ones I came into this problem. A first I thought it was a malfunction on my code, so I tried to create shared objects and collections directly with with. This is the thing:

This works fine: one shared object inside another
<code 4D>
$o_twoLevels:=New shared object(“letter”;“a”;“number”;New shared object(“one”;1))

</code 4D>

If I embed a another object to the second level object I get a -10724 error (this object already belong to another shared object):
<code 4D>
$o_threeLevels:=New shared object(“letter”;“a”;“number”;New shared object(“one”;1;“color”;New shared object(“black”;0)))
</code 4D>

On standard objects and collection of course this problem does no exist.

Am I doing something wrong or is this a malfunction on shared objects or is it a “standard behavior”?

Product :4D
4D : v17R2 64 bit (did not try 32 bit)


you can have as many levels of chained shared objects as you like,
but you need to be strategic how you build them.

it would be good to review the doc. and understand the concept of single/multiple lock identifiers.
it would also be great to introspect your shared objects in the debugger, which show their locker IDs.

but it might be easier to learn from example.

the reason your code doesn’t work is because you have nested “New shared object”.
the 3rd innermost call creates a single object, which is immediate attached to the 2nd level,
making it a multiple object with its own locker ID.

the outermost call can’t accept it as a new member,
because a multiple object can’t join a different multiple object.

if that sounds complicated,
just take a step back and create your shared object procedurally.

<code 4D>
$color:=New shared object(“black”;0)
$number:=New shared object(“one”;1;“color”;null)
$o_threeLevels:=New shared object(“letter”;“a”;“number”;null)

Use ($o_threeLevels)
End use
</code 4D>

[]26573351;“Your comment here…”[/]

Thanks Miyako!
I had read the doc but clearly I didn’t understand it.