- DelphiTools - https://www.delphitools.info -

Globals Storages in DWScript

logoDWSDWScript [1]has a “Globals” facility that allows storing and sharing data across scripts living in the same executable.

The first are Global Vars, and is a Key-Value storage, the second are Global Queues, which are LIFO/FIFO named queues. Both are thread-safe and high performance.

Enabling Support for Globals

To support them, just have dwsGlobalVarsFunctions in one of your project’s uses clause.

From that point on, all your scripts will have access to the Global Vars and Queues.

Delphi-side utilities are also exposed in that unit, and provide ability for the host application to debug, backup, etc.

Global Vars

Globals Vars storage is accessed through the ReadGlobalVar(name) and WriteGlobalVar(name, value) functions. They allow reading and writing a value by name, in an in-memory dictionary. Read & write operations are atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces [2].

Here is the complete list of functions:

Global Queues

Global Queues are named chains of values which can be used both as a LIFO and FIFO queues. Writing or reading from a queue is thread-safe and atomic.

While they’re quite self-sufficient on their own, you’ll usually want to access them through a minimal wrapper functions that’ll handle namespaces [2].

Here is the complete list of functions: