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

Associative Arrays in DWScript

dwsAssociate Arrays (aka dictionary) are now in experimental form in the DWScript repository [1].

They extend the array type declarations: in the same way you could declare an “array [TEnum] of Xxx” you can now declare an “array [String] of Xxx”, and not just with strings but with any type on either side.

The declaration syntax is

array [<some key type>] of <some element type>

The key type is matched on strict equality rules:

The basic usage is as follow:

var a : array [String] of Float;
a['pi'] := 3.141592; // add or replace
v := a['pi']; // read access

If a key is not present in an associative array, the value is that of the default for the type (zero for numeric, empty string, nil, etc.).

There are currently just two pseudo-methods supported: