# Config A full featured JSON config writer and reader. - - - (TConfigJSON)= ## type TConfigJSON ```pascal TConfigJSON = record Path: String; JSON: TJSONObject; end; ``` - - - ## TConfigJSON.GetConfig ```pascal function TConfigJSON.GetConfig(): TJSONObject; ``` Helper method to return the current TConfigJSON.Path file as a TJSONObject. You probably don't need to use this directly. - - - ## TConfigJSON.Free ```pascal procedure TConfigJSON.Free(); ``` Used to free your `TConfigJSON`. 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). - - - ## TConfigJSON.Setup ```pascal procedure TConfigJSON.Setup(jsonFile: String); ``` Main method to setup your `TConfigJSON` - - - ## TConfigJSON.DeleteConfig ```pascal procedure TConfigJSON.DeleteConfig(); ``` Delete your `TConfigJSON` from disk. - - - ## TConfigJSON.SaveConfig ```pascal procedure TConfigJSON.SaveConfig(); ``` Used to save your `TConfigJSON`. By default, this is always called automatically whenever the config is modified by the {ref}`TConfigJSON.Put()` methods. - - - ## TConfigJSON.Put ```pascal procedure TConfigJSON.Put(key, value: String; save: Boolean = True); procedure TConfigJSON.Put(key: String; value: Int32; save: Boolean = True); overload; procedure TConfigJSON.Put(key: String; value: Double; save: Boolean = True); overload; procedure TConfigJSON.Put(key: String; value: Boolean; save: Boolean = True); overload; procedure TConfigJSON.Put(key: String; value: Pointer; save: Boolean = True); overload; ``` This should be self explanatory. Put a `key` and a `value` pair into your `TConfigJSON`. 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. - - - ## TConfigJSON.Has ```pascal function TConfigJSON.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. - - - ## TConfigJSON.Get ```pascal function TConfigJSON.GetString(key: String): String; function TConfigJSON.GetInt(key: String): Int32; function TConfigJSON.GetDouble(key: String): Double; function TConfigJSON.GetBoolean(key: String): Boolean; function TConfigJSON.GetNull(key: String): Boolean; function TConfigJSON.GetObject(key: String): TJSONObject; function TConfigJSON.GetArray(key: String): TJSONArray; ``` This should be self explanatory. Returns the value of a `key` in your `TConfigJSON`. 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. - - - ## TConfigJSON.Remove ```pascal procedure TConfigJSON.Remove(key: String); ``` Remove a `key` and it's respective `value` from your `TConfigJSON`. - - - ## TConfigJSON.ToString ```pascal function TConfigJSON.ToString(indentFactor: Int32 = 2): String; ``` Returns a string version of your `TConfigJSON`. Example: ```pascal WriteLn MyConfig.ToString(); ``` - - - (TConfigINI)= ## type TConfigINI ```pascal TConfigINI = record Path: String; FileName: String; end; ``` Example: ```pascal ConfigINI.Setup('MyScriptSettings.ini'); // Set file path ConfigINI.Put('GUISettings', 'UsePoolPOH', 'True'); // Write setting WriteLn(ConfigINI.Get('GUISettings', 'UsePoolPOH')); // Read setting WriteLn(ConfigINI.GetKeys('GUISettings')); // List all keys in 'GUISettings' ``` - - - ## TConfigINI.Setup ```pascal procedure TConfigINI.Setup(ConfigName: String); ``` Initializes configuration path and filename. Example: ```pascal ConfigINI.Setup('MyScriptSettings.ini'); ``` - - - ## TConfigINI.Put ```pascal procedure TConfigINI.Put(Section, KeyName, Value: String); ``` Writes a single key-value pair to a specified section. Example: ```pascal ConfigINI.Put('GUISettings', 'UsePoolPOH', 'True'); ``` - - - ## TConfigINI.Get ```pascal function TConfigINI.Get(Section, KeyName: String): String; ``` Retrieves a single value by key from a specified section. Example: ```pascal WriteLn(ConfigINI.Get('GUISettings', 'UsePoolPOH')); ``` - - - ## TConfigINI.GetKeys ```pascal function TConfigINI.GetKeys(Section: String): TStringArray; ``` Retrieves all keys from a specified section. Example: ```pascal WriteLn(ConfigINI.GetKeys('GUISettings')); ``` - - - ## TConfigINI.Remove ```pascal procedure TConfigINI.Remove(Section, KeyName: String); ``` Removes a single key-value pair from a specified section. Example: ```pascal ConfigINI.Remove('GUISettings', 'UsePoolPOH')); ``` - - - ## TConfigINI.DeleteConfig ```pascal procedure TConfigINI.DeleteConfig(); ``` Deletes the entire configuration file. Example: ```pascal ConfigINI.DeleteConfig(); ```