KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Store constant values and utility methods in Storage for global access
PRODUCT: 4D | VERSION: 17 R3 | PLATFORM: Mac & Win
Published On: April 24, 2019

The new Storage object feature of V17 allows sharing any object or collection across all processes including preemptive processes. For application written in preemptive mode, Storage can be used in place of intercrosses variable to share data. A common use case of Storage would be holding constant values needed in application. The best place to initialize the Storage object is in the On Startup database method:

Use (Storage)
  Storage.Math:=New shared object"PI";3.141592653589793)
End use


The value of Storage.Math.PI can be accessed anywhere within the application:

C_REAL($pi)
$pi:=Storage.Math.PI
//result: 3.14159265359


In V17R3 and above, formula encapsulated in objects, that also includes Storage objects. Besides constant values, we can now use the New formula command to store utility methods as formulas that will be used repeatedly in the application:

Use (Storage)
  Storage.Math:=New shared object(“addition”;New formula($1+$2))
End use


The new formula, Storage.Math.addition, can be called anywhere within the application:

C_REAL($result)
$result:=Storage.Math.addition(1;2)
//result: 3


One sub-object can encapsulate many formulas which provides a clean, organized alternative of project methods to store utility methods. Any value and formula are accessible on current machine across all processes