Tech Tip: When to use the "Use (Storage)" code block
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: April 18, 2019
There are certain scenarios where the "Use (Storage)" code block is required and other scenarios where it is not necessary. For example, a new shared collection is initialized and the collection is about to be modified.
// Initialize new shared collection Use (Storage) Storage.test:=New shared collection End use |
There are two ways to modify the existing shared collection or shared object: member functions or assignment. In this example, if the shared collection is modified using a member function like collection.push, only the Use (Storage.test) code block is required as shown below:
// Use (Storage) is not required since push method directly modifies the collection Use (Storage.test) Storage.test.push(1) End use |
If the shared collection/object is reassigned to a new value, both Use (Storage) and Use (Storage.test) are required.
// Both use code blocks are required when assigning new values Use (Storage) Use (Storage.test) Storage.test:=New shared collection End use End use |
Otherwise, using only Use (Storage.test) on reassignment will result in an error.
// Error Use (Storage.test) Storage.test:=New shared collection End use |