The script settings object gives you access to a list in memory were you can save temporary or permenent settings. All settings are saved to file when the program exits, or if you use the ScriptSettings.UpdateFile method.
Data format
Settings are stored in Ini file format using key-value pairs stored in sections. The key may be refered to as name, property or identifier.
E.g
[Options]
Name=John
Number=100
Show=1
[Edit]
Indent=0
Wordwrap=1
[...] is the section name. Key-value pairs are grouped under a section. Keys and values are seperated by an equal sign. E.g Name=John.
Write a value
To write a value use one of the write methods, e.g
ScriptSettings.WriteString("Options", "LastName", "Smith");
Read a value
Read a value using a read method, e.g.
bool wrap = ScriptSettings.ReadBool("Edit", "Wordwrap", false);
Temp sections
A temp section can be used if you don't want the settings to be stored on file. [Temp] sections are only stored in memory and never saved to file.
E.g. ScriptSettings.WriteBool("Temp","ShowUI",true).
Save settings to file
All settings are stored to file when the program exits. But you can also use the method ScriptSettings.UpdateFile to save evrything in memory to file.
The file is stored in <AppData>\Roaming\RJ TextEd\Data\ScriptSettings.Ini.
Methods
Read a value
Syntax
function ReadBool(const Section, Ident: string; Default: Boolean): Boolean
function ReadDateTime(const Section, Name: string; Default: TDateTime): TDateTime
function ReadDate(const Section, Name: string; Default: TDateTime): TDateTime
function ReadFloat(const Section, Name: string; Default: Double): Double
function ReadInteger(const Section, Ident: string; Default: Integer): Integer
function ReadString(const Section, Ident, Default: string): string
function ReadTime(const Section, Name: string; Default: TDateTime): TDateTime
Description
Read a value stored in settings. "Default" is a default value - used if no value is found in settings.
Example
// C++ script
int method = ScriptSettings.ReadInteger("Convert", "Method", 0);
Write a value
Syntax
procedure WriteBool(const Section, Ident: string; Value: Boolean)
procedure WriteDateTime(const Section, Name: string; Value: TDateTime)
procedure WriteDate(const Section, Name: string; Value: TDateTime)
procedure WriteFloat(const Section, Name: string; Value: Double)
procedure WriteInteger(const Section, Ident: string; Value: Integer)
procedure WriteString(const Section, Ident, Value: String)
procedure WriteTime(const Section, Name: string; Value: TDateTime)
Description
Write a value in settings.
Example
// C++ script
int method = 2;
ScriptSettings.WriteInteger("Convert", "Method", method);
Delete a key
Syntax
DeleteKey(const Section, Ident: String)
Description
Delete a key and value in settings.
Example
// C++ script
ScriptSettings.DeleteKey("Convert", "Method");
Erase a section
Syntax
EraseSection(const Section: string)
Description
Erase an entire section, including keys and values.
Example
// C++ script
ScriptSettings.EraseSection("Convert");
Check if a value exists
Syntax
ValueExists(const Section, Ident: string): Boolean
Description
See if a value exist in settings.
Example
// C++ script
if (ScriptSettings.ValueExists("Convert", "Method")) {
}
Check if a section exists
Syntax
SectionExists(const Section: string): Boolean
Description
See if a section exists in settings.
Example
// C++ script
if (ScriptSettings.SectionExists("Convert")) {
}
Save to file (update)
Syntax
UpdateFile
Description
Save all settings in memory to file (except the [Temp] section).
Example
// C++ script
ScriptSettings.UpdateFile;
|