Config

A full featured JSON config writer and reader.


type TWaspConfig

TWaspConfig = record
  Path: String;
  JSON: TJSONObject;
end;

Config.GeTWaspConfig()

function TWaspConfig.GeTWaspConfig(): TJSONObject;

Helper method to return the current TWaspConfig.Path file as a TJSONObject. You probably don’t need to use this directly.


Config.Free()

procedure TWaspConfig.Free();

Used to free your TWaspConfig. It’s automatically called on script termination, but you may call it sooner if you wish to unlock the ram used by this (which should be minimal).


Config.Setup

procedure TWaspConfig.Setup(jsonFile: String);

Main method to setup your TWaspConfig


Config.DeleteConfig()

procedure TWaspConfig.DeleteConfig();

Delete your TWaspConfig from disk.


Config.SaveConfig()

procedure TWaspConfig.SaveConfig();

Used to save your TWaspConfig. By default, this is always called automatically whenever the config is modified by the TWaspConfig.Put() methods.


Config.Put()

procedure TWaspConfig.Put(key, value: String; save: Boolean = True);
procedure TWaspConfig.Put(key: String; value: Int32; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; value: Double; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; value: Boolean; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; values: TStringArray; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; values: TIntegerArray; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; values: TDoubleArray; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; values: TBoolArray; save: Boolean = True); overload;
procedure TWaspConfig.Put(key: String; value: Pointer; save: Boolean = True); overload;

This should be self explanatory. Put a key and a value pair into your TWaspConfig. The pointer version of the method is the only one that might need a little bit more knowledge of Simba’s lower JSON methods and/or pointers but you can use it to place a value that is another JSON object or a JSON array.


Config.Has()

function TWaspConfig.Has(key: String; nullIsValid: Boolean = True): Boolean;

Checks if a key exists. nullIsValid is true by default when set to false this will return false if the key exists but is set to null.


Config.Get()

function TWaspConfig.GetString(key: String): String;
function TWaspConfig.GetInt(key: String): Int32;
function TWaspConfig.GetDouble(key: String): Double;
function TWaspConfig.GetBoolean(key: String): Boolean;
function TWaspConfig.GetNull(key: String): Boolean;
function TWaspConfig.GetStringArray(key: String): TStringArray;
function TWaspConfig.GetIntArray(key: String): TIntegerArray;
function TWaspConfig.GetDoubleArray(key: String): TDoubleArray;
function TWaspConfig.GetBooleanArray(key: String): TBoolArray;
function TWaspConfig.GetObject(key: String): TJSONObject;

This should be self explanatory. Returns the value of a key in your TWaspConfig. The Object version of the method is the only one that might need a little bit more knowledge of Simba’s lower JSON methods and/or pointers but you can use it to return a JSON object or a TJSONArray of TJSONObjects.


Config.Remove()

procedure TWaspConfig.Remove(key: String);

Remove a key and it’s respective value from your TWaspConfig.


Config.ToString()

function TWaspConfig.ToString(indentFactor: Int32 = 2): String;

Returns a string version of your TWaspConfig.

Example:

WriteLn MyConfig.ToString();