Getting object data into shared object or shared collection

Hi

Is there an easy way to load object data (eg: from an object field) into a shared object?

I wanted to load object data from some records into an object within Storage on 4D Remote at the point of user login.

It seems quite hard to do that.

Am I missing a trick?

Thanks

Keith

Hi,

Is that Tech Note what you are looking for? https://kb.4d.com/assetid=78197Tech Tip: Assign an object to a shared object>

Hi Gabriel

That is helpful, thanks. The article says it supports all property types including collections.

Collections do not work with that code, for sure. I think I can adapt it to handle that.

Thank you.

Best regards

Keith

https://forums.4d.com/Post/FR/26781888/2/26802852#26802557Here> is some code I wrote (sorry in French)

Thanks Manuel. I adapted the tech tip to make methods to do a copy of object or collection with nested objects or collections

<code 4D>
// Method: OB_CopyObject
// $1: Object to copy from
// $2: Shared Object to copy to

C_OBJECT($1;$2)
C_LONGINT($nType;$counter)

ARRAY TEXT($arrNames;0)

OB GET PROPERTY NAMES($1;$arrNames)
For ($counter;1;Size of array($arrNames))
$nType:=OB Get type($1;$arrNames{$counter})
Case of
: ($nType=Is object)
$2[$arrNames{$counter}]:=New shared object
Use ($2[$arrNames{$counter}])
OB_CopyObject ($1[$arrNames{$counter}];$2[$arrNames{$counter}])
End use
: ($nType=Is collection)
$2[$arrNames{$counter}]:=New shared collection
Use ($2[$arrNames{$counter}])
OB_CopyCollection ($1[$arrNames{$counter}];$2[$arrNames{$counter}])
End use
Else
$2[$arrNames{$counter}]:=$1[$arrNames{$counter}]
End case
End for

</code 4D>

<code 4D>
// Method: OB_CopyCollection
// $1: Collection to copy from
// $2: Shared Collection to copy to

C_COLLECTION($1;$2)
C_LONGINT($nSize;$nCount;$nElement;$nType)

$nSize:=$1.length

For ($nCount;1;$nSize)
$nElement:=$nCount-1
$nType:=Value type($1[$nElement])
Case of
: ($nType=Is object)
$2[$nElement]:=New shared object
Use ($2[$nElement])
OB_CopyObject ($1[$nElement];$2[$nElement])
End use
: ($nType=Is collection)
$2[$nElement]:=New shared collection
Use ($2[$nElement])
OB_CopyCollection ($1[$nElement];$2[$nElement])
End use
Else
$2[$nElement]:=$1[$nElement]
End case
End for

</code 4D>