UserSettings

Overview

Represents a configuration file.

UserSettings is a singleton class, use Default method to get access to an instance of the class.

Use case

You can use UserSettings class when you need to store preferences, for example:

method SaveSettings;
begin
  Sugar.UserSettings.Default.Write("StoreLoginName", true);
  Sugar.UserSettings.Default.Write("LastLoginName", "User");
  Sugar.UserSettings.Default.Save;
end;

method LoadSettings;
begin
  writeLn(Sugar.UserSettings.Default.Read("StoreLoginName", false));
  writeLn(Sugar.UserSettings.Default.Read("LastLoginName", ""));
end;

Output:

True
User

Location

  • Reference: Sugar
  • Namespace: Sugar

 

Clear  mapped

Removes all settings.

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Default

Returns default instance of the class.

 

class method Default: UserSettings

 

static UserSettings Default()

 

static func Default() -> UserSettings

 

static UserSettings Default()

Keys

Gets a list of all keys stored in settings.

 

property Keys: array of String read;

 

String[] Keys { get; }

 

var Keys: String... { get{} }

 

String[] Keys { __get; }

Read (String, String): String  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: String): String

 

String Read(String Key, String DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: String) -> String

 

String Read(String Key, String DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Boolean): Boolean  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Boolean): Boolean

 

Boolean Read(String Key, Boolean DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Boolean) -> Boolean

 

Boolean Read(String Key, Boolean DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Double): Double  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Double): Double

 

Double Read(String Key, Double DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Double) -> Double

 

Double Read(String Key, Double DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Int32): Int32  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Int32): Int32

 

Int32 Read(String Key, Int32 DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Int32) -> Int32

 

Int32 Read(String Key, Int32 DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Remove  mapped

Removes a setting with a specified key.

 

method Remove(Key: String)

 

void Remove(String Key)

 

func Remove(_ Key: String)

 

void Remove(String Key)

Parameters:

  • Key: The key for a setting.

Save  mapped

Causes any buffered data to be written to a settings storage.

 

method Save

 

void Save()

 

func Save()

 

void Save()

Write (String, String)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: String)

 

void Write(String Key, String Value)

 

func Write(_ Key: String, _ Value: String)

 

void Write(String Key, String Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Boolean)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Boolean)

 

void Write(String Key, Boolean Value)

 

func Write(_ Key: String, _ Value: Boolean)

 

void Write(String Key, Boolean Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Double)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Double)

 

void Write(String Key, Double Value)

 

func Write(_ Key: String, _ Value: Double)

 

void Write(String Key, Double Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Int32)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Int32)

 

void Write(String Key, Int32 Value)

 

func Write(_ Key: String, _ Value: Int32)

 

void Write(String Key, Int32 Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

 

Keys

Gets a list of all keys stored in settings.

 

property Keys: array of String read;

 

String[] Keys { get; }

 

var Keys: String... { get{} }

 

String[] Keys { __get; }

 

Default

Returns default instance of the class.

 

class method Default: UserSettings

 

static UserSettings Default()

 

static func Default() -> UserSettings

 

static UserSettings Default()

 

Clear  mapped

Removes all settings.

 

method Clear

 

void Clear()

 

func Clear()

 

void Clear()

Read (String, String): String  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: String): String

 

String Read(String Key, String DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: String) -> String

 

String Read(String Key, String DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Boolean): Boolean  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Boolean): Boolean

 

Boolean Read(String Key, Boolean DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Boolean) -> Boolean

 

Boolean Read(String Key, Boolean DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Double): Double  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Double): Double

 

Double Read(String Key, Double DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Double) -> Double

 

Double Read(String Key, Double DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Read (String, Int32): Int32  mapped

Reads a setting with specified key. If setting with that key can not be found then specified default value is returned.

 

method Read(Key: String; DefaultValue: Int32): Int32

 

Int32 Read(String Key, Int32 DefaultValue)

 

func Read(_ Key: String, _ DefaultValue: Int32) -> Int32

 

Int32 Read(String Key, Int32 DefaultValue)

Parameters:

  • Key: The key for a setting.
  • DefaultValue: The default value for a setting.

Remove  mapped

Removes a setting with a specified key.

 

method Remove(Key: String)

 

void Remove(String Key)

 

func Remove(_ Key: String)

 

void Remove(String Key)

Parameters:

  • Key: The key for a setting.

Save  mapped

Causes any buffered data to be written to a settings storage.

 

method Save

 

void Save()

 

func Save()

 

void Save()

Write (String, String)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: String)

 

void Write(String Key, String Value)

 

func Write(_ Key: String, _ Value: String)

 

void Write(String Key, String Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Boolean)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Boolean)

 

void Write(String Key, Boolean Value)

 

func Write(_ Key: String, _ Value: Boolean)

 

void Write(String Key, Boolean Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Double)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Double)

 

void Write(String Key, Double Value)

 

func Write(_ Key: String, _ Value: Double)

 

void Write(String Key, Double Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.

Write (String, Int32)  mapped

Writes a setting with specified key and value. If setting with that key already exists then its value is overriden.

 

method Write(Key: String; Value: Int32)

 

void Write(String Key, Int32 Value)

 

func Write(_ Key: String, _ Value: Int32)

 

void Write(String Key, Int32 Value)

Parameters:

  • Key: The key for a setting.
  • Value: The value for a setting.