On Sep 9, 2019, at 9:55 PM, Keisuke Miyako via 4D_Tech <4d_tech@lists.4d.com> 
wrote:
> 
>> So it looks like you can’t .push() a shared object onto a shared collection.
> 
> not quite.
> 
> a shared object is either single (solo) or multiple (once belonged to a group)
> if an object joins a group, it is free to leave it, but it can't join another 
> group.
> [snip]
> in your case, the problem is that you add $sharedObj to $catalogObj,
> then $catalogObj to Storage.
> 
> if you reverse the order, that is,
> add $catalogObj to Storage first,
> then $sharedObj to $catalogObj later,
> it should work.

$catalogObj is a sub-object from the results of an API call with HTTP Get. So 
it is an existing non-shared object (I.e. not manually created with keys and 
values by 4D code). I want to add that object to a shared collection so it can 
be put into Storage. 

The only reason $sharedObj exists is because I need to copy all attributes of 
$catalogObj to $sharedObj so I can add to a shared collection. (Note: I had an 
error in the first code snippet below; $sharedObj should have been assigned a 
New Shared Object.)

If I use the code in the reference KB article, copying the non-shared 
$catalogObj to a new shared object $sharedObj, I can’t add $sharedObj to the 
shared collection. Presumably I could add that shared object to Storage as a 
root-level object, but I want a shared collection of those objects.

It looks like collection.push() is actually copying the shared object, and that 
results in an error because of the shared object's __LockerID property being 
duplicated. However, we don’t seem to have any other way to add objects to a 
collection besides .unshift(), which probably does the same as .push(). It 
seems like .push() should just add the shared object reference to the shared 
collection, not copy it, especially for shared objects.

If collection.push($myObj) actually copies $myObj, this should be clearly 
documented. If the general rule is that working with objects is by reference, 
we need to know when objects are copied instead of referenced.

Jim Crate


>> 2019/09/10 13:13、Jim Crate via 4D_Tech <4d_tech@lists.4d.com>のメール:
>> 
>> So what doesn’t work is:
>> 
>> $sharedObj:=New Shared Object
>> OB_CopyToSharedObject ($catalogObj;$sharedObj)
>> Use (Storage.MySharedCollection)
>> Storage.MySharedCollection.push($sharedObj)
>> End use
>> 
>> 
>> What does work is:
>> 
>> Storage.MySharedCollection.push(New shared object)
>> Use (Storage.MySharedCollection[Storage.MySharedCollection.length-1])
>> OB_CopyToSharedObject 
>> ($catalogObj;Storage.MySharedCollection[Storage.MySharedCollection.length-1])
>> End use
> 
> 
> 
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**********************************************************************

Reply via email to