4D Blog

Home Product Objects Corner: easy sharing & other good news

Objects Corner: easy sharing & other good news

May 19, 2020

Product

How many times have you gotten the “Not supported value type in a shared object” error when trying to put an object into a shared object?

What did you do? Write longer code to turn your innocent object into a shared one, perhaps iterating over all of its properties?

How about transferring a shared object from one shared group to another?

 

An interesting thing about objects: you already know they can be used as a hash map (a key/value system), but what about gettings all the keys or all the values with a single line of code?

Keep reading, because 4D v18 R3 is out and brings good news!

COPY shared objects and collections

copy an object as shared

The OB Copy() command has been enhanced to accept a new option which can have the value: ck shared 

In the example below, the $person object is copied as a shared object into the $copy object.

Then, we can put the $copy object into the $personsList shared object.

C_OBJECT($person;$copy;$personsList)
C_TEXT($text)
 
$text:=Document to text(Get 4D folder(Current resources folder)+"person.txt")
//$person is a standard object
$person:=JSON Parse($text)
 
$personsList:=New shared object()
 
//$copy is a shared object
$copy:=OB Copy($person;ck shared)
 
Use ($personsList)
//We can put $copy in $personsList because $copy is a shared object
$personsList.person:=$copy
End use

assign a shared object from a shared group to another

The OB Copy() command has also been enhanced to accept a new parameter: groupWith (which must be a shared object or a shared collection).

Passing the groupWith parameter allows putting the copied object into the same shared group as groupWith.

In the example below, $sharedObj and $sharedColl belong to two separate shared groups.

We can’t put $sharedObj into $sharedColl without getting an error, but we can easily copy $sharedObj into a new object belonging to the same shared group as $sharedColl.

C_OBJECT($sharedObj;$objCopy)
C_COLLECTION($sharedColl)
 
//$sharedObj belongs to a shared group

$sharedObj:=New shared object("lastname";"Smith";"address";New shared object("city";"New York"))
 
//$sharedColl belongs to another shared group

$sharedColl:=New shared collection(New shared object("lastname";"Brown"))
 
//$objCopy is in the same shared group as $sharedColl

$objCopy:=OB Copy($sharedObj;ck shared;$sharedColl)
 
//So we can put $objCopy into $sharedColl without error

Use ($sharedColl)
$sharedColl.push($objCopy)
End use

 

and what about shared collections?

The examples above are related to the OB Copy() command.

The collection.copy() member method has been enhanced in the exact same way.

handle an object as a hash map

There are new commands to make handling an object as a hash map easier. If you have objects whose property names contain dynamic data, these commands are for you!

Let’s explain this with a single example.

Consider this $persons object containing firstnames as a property name and age as a property value:

C_OBJECT($persons)
$persons:=New object
$persons["John"]:=42 // John is 42
$persons["Andy"]:=24 // Andy is 24
$persons["Mary"]:=30 // Mary is 30
$persons["Paul"]:=50 // Paul is 50
$persons["Fred"]:=51// Fred is 51

OB Keys command

This command returns the property names of an object as a collection:

ALERT("There are "+String(OB Keys($persons).length)+" persons")

OB Values command

This command returns the property values of an object as a collection:

ALERT("The age average is "+String(OB Values($persons).average()))

OB Entries command

This command returns a collection of objects with key properties (property name) and value (property value):

C_COLLECTION($agesOK)
 
$agesOK:=OB Entries($persons).query("value>:1";45)
ALERT("There are "+String($agesOK.length)+" persons who are over 45")
ALERT("Their names are: "+$agesOK.extract("key").join("-"))

Using an object as shown above, provides quick, direct access to data like when using an index.

It’s faster than using a collection of objects with firstname and age properties.

Also note that those commands return a collection. This allows us to use all the member methods available on collections (like average(), query(), …).

 

 

Discuss

Tags Objects, Preemptive, Programming, Shared collection, Shared object, v18 R3, v19

Latest related posts

  • February 3, 2026

    4D Write Pro – Adding a margin automatically when bullets are set using standard actions

  • January 22, 2026

    Transform Static Documents into Actionable Knowledge with AIKit

  • January 22, 2026

    Deploy Fluent UI effortlessly in your 4D applications

Avatar
Marie-Sophie Landrieu-Yvert
- Product Owner - Marie-Sophie Landrieu-Yvert joined the 4D Product team as a Product Owner in 2017. In this role, she is responsible for writing user stories and translating them into functional specifications. She also ensures that the delivered feature implementation meets the customer's needs. Marie-Sophie graduated from the engineering school ESIGELEC and began her career as an engineer at IBM in 1995. She took part in various projects (maintenance and development projects) and worked as a COBOL developer. She then moved on to work as a UML designer and Java developer. More recently, her main responsibilities included analyzing and writing functional requirements, and coordinating business and development teams.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • Release infos
  • 4D View Pro
  • 4D Write Pro
  • Email, Microsoft 365, Gmail
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • 4D Qodly Pro
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 21 21 R2 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Google Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience vscode Web Word processor
Subscribe to 4D Newsletter

© 2026 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy