Class TCastleConfig
Unit
Declaration
type TCastleConfig = class(TXMLConfig)
Description
Store configuration in XML format. Adds various Castle Game Engine extensions to the ancestor TXMLConfig class:
load/save from an URL or a TStream (not just a filename),
load/save to the default config file location (for user preferences),
load/save more types (floats, vectors, colors, URLs, multiline text...),
PathElement and MakePathElement utility, to use powerful DOM functions when needed to process something more complex,
encrypt/descrypt contents, just use BlowFishKeyPhrase property (this is actually built-in in our modified TXMLConfig).
See https://castle-engine.io/manual_user_prefs.php for more documentation.
Hierarchy
- TObject
- TPersistent
- TComponent
- TXMLConfig
- TCastleConfig
Overview
Methods
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function GetInteger(const APath: string; const ADefaultValue: Integer): Integer; overload; |
|
function GetInteger(const APath: String): Integer; overload; |
|
function GetBoolean(const APath: String): Boolean; overload; |
|
function GetStringNonEmpty(const APath: string): string; |
|
function GetNonEmptyValue(const APath: string): string; deprecated 'use GetStringNonEmpty'; |
|
function GetFloat(const APath: string; const ADefaultValue: Float): Float; overload; |
|
function GetFloat(const APath: string): Float; overload; |
|
procedure SetFloat(const APath: string; const AValue: Float); |
|
procedure SetDeleteFloat(const APath: string; const AValue, ADefaultValue: Float); |
|
function GetInt64(const APath: string; const ADefaultValue: Int64): Int64; overload; |
|
function GetInt64(const APath: string): Int64; overload; |
|
procedure SetInt64(const APath: string; const AValue: Int64); |
|
procedure SetDeleteInt64(const APath: string; const AValue, ADefaultValue: Int64); |
|
function GetVector2(const APath: string; const ADefaultValue: TVector2): TVector2; overload; |
|
function GetVector2(const APath: string): TVector2; overload; |
|
procedure SetVector2(const APath: string; const AValue: TVector2); overload; |
|
procedure SetDeleteVector2(const APath: string; const AValue, ADefaultValue: TVector2); overload; |
|
function GetVector3(const APath: string; const ADefaultValue: TVector3): TVector3; overload; |
|
function GetVector3(const APath: string): TVector3; overload; |
|
procedure SetVector3(const APath: string; const AValue: TVector3); overload; |
|
procedure SetDeleteVector3(const APath: string; const AValue, ADefaultValue: TVector3); overload; |
|
function GetVector4(const APath: string; const ADefaultValue: TVector4): TVector4; overload; |
|
function GetVector4(const APath: string): TVector4; overload; |
|
procedure SetVector4(const APath: string; const AValue: TVector4); overload; |
|
procedure SetDeleteVector4(const APath: string; const AValue, ADefaultValue: TVector4); overload; |
|
function GetValue(const APath: string; const ADefaultValue: TVector2): TVector2; overload; deprecated 'use GetVector2'; |
|
procedure SetValue(const APath: string; const AValue: TVector2); overload; deprecated 'use SetVector2'; |
|
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector2); overload; deprecated 'use SetDeleteVector2'; |
|
function GetValue(const APath: string; const ADefaultValue: TVector3): TVector3; overload; deprecated 'use GetVector3'; |
|
procedure SetValue(const APath: string; const AValue: TVector3); overload; deprecated 'use SetVector3'; |
|
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector3); overload; deprecated 'use SetDeleteVector3'; |
|
function GetValue(const APath: string; const ADefaultValue: TVector4): TVector4; overload; deprecated 'use GetVector4'; |
|
procedure SetValue(const APath: string; const AValue: TVector4); overload; deprecated 'use SetVector4'; |
|
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector4); overload; deprecated 'use SetDeleteVector4'; |
|
function GetColorRGB(const APath: string; const ADefaultColor: TCastleColorRGB): TCastleColorRGB; overload; |
|
function GetColorRGB(const APath: string): TCastleColorRGB; overload; |
|
procedure SetColorRGB(const APath: string; const AColor: TCastleColorRGB); overload; |
|
procedure SetDeleteColorRGB(const APath: string; const AColor, ADefaultColor: TCastleColorRGB); overload; |
|
function GetColor(const APath: string; const ADefaultColor: TCastleColor): TCastleColor; overload; |
|
function GetColor(const APath: string): TCastleColor; overload; |
|
procedure SetColor(const APath: string; const AColor: TCastleColor); overload; |
|
procedure SetDeleteColor(const APath: string; const AColor, ADefaultColor: TCastleColor); overload; |
|
function PathElement(const APath: string; const RaiseExceptionWhenMissing: boolean = false): TDOMElement; |
|
function MakePathElement(const APath: string): TDOMElement; |
|
function PathChildren(const APath: string; const ChildName: string): TDOMNodeList; deprecated 'use PathChildrenIterator'; |
|
function PathChildrenIterator(const APath: string; const ChildName: string): TXMLElementIterator; |
|
function GetUrl(const APath: string; const EmptyIfNoAttribute: boolean = false): string; |
|
function GetMultilineText(const APath: string; const DefaultValue: String): string; overload; |
|
function GetMultilineText(const APath: string): string; overload; |
|
procedure NotModified; |
|
procedure MarkModified; |
|
function Document: TDOMDocument; |
|
procedure AddLoadListener(const Listener: TCastleConfigEvent); |
|
procedure AddSaveListener(const Listener: TCastleConfigEvent); |
|
procedure RemoveLoadListener(const Listener: TCastleConfigEvent); |
|
procedure RemoveSaveListener(const Listener: TCastleConfigEvent); |
|
procedure Load; overload; |
|
procedure Load(const AUrl: String); overload; |
|
procedure Load(const Stream: TStream; const PretendUrl: String); overload; |
|
procedure LoadFromString(const Data: string; const PretendUrl: String); |
|
procedure Save; overload; |
|
procedure Save(const Stream: TStream); overload; |
|
function SaveToString: string; |
Properties
property IsLoaded: boolean read FLoaded; |
Description
Methods
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function GetInteger(const APath: string; const ADefaultValue: Integer): Integer; overload; |
|
Integer values reading/writing to config file. Exceptions raised
|
function GetInteger(const APath: String): Integer; overload; |
|
This item has no description. |
function GetBoolean(const APath: String): Boolean; overload; |
|
Get a required boolean attribute, raise exception if missing or invalid. Exceptions raised
|
function GetStringNonEmpty(const APath: string): string; |
|
Get a required, non-empty string value. Value must exist and cannot be empty in XML file. Exceptions raised
|
function GetNonEmptyValue(const APath: string): string; deprecated 'use GetStringNonEmpty'; |
|
Warning: this symbol is deprecated: use GetStringNonEmpty This item has no description. |
function GetFloat(const APath: string; const ADefaultValue: Float): Float; overload; |
|
Float values reading/writing to config file. Note: for powerful reading of float expressions, consider using
Exceptions raised
|
function GetFloat(const APath: string): Float; overload; |
|
This item has no description. |
procedure SetFloat(const APath: string; const AValue: Float); |
|
This item has no description. |
procedure SetDeleteFloat(const APath: string; const AValue, ADefaultValue: Float); |
|
This item has no description. |
function GetInt64(const APath: string; const ADefaultValue: Int64): Int64; overload; |
|
Int64 values reading/writing to config file. Exceptions raised
|
function GetInt64(const APath: string): Int64; overload; |
|
This item has no description. |
procedure SetInt64(const APath: string; const AValue: Int64); |
|
This item has no description. |
procedure SetDeleteInt64(const APath: string; const AValue, ADefaultValue: Int64); |
|
This item has no description. |
function GetVector2(const APath: string; const ADefaultValue: TVector2): TVector2; overload; |
|
2D, 3D, 4D vectors reading/writing to config file. They should be expressed in XML like <myVector x="1" y="2" z="3" w="4" />
You can read such vector by GetVector('example/path/to/myVector', Vector4(0, 0, 0, 0));
|
function GetVector2(const APath: string): TVector2; overload; |
|
This item has no description. |
procedure SetVector2(const APath: string; const AValue: TVector2); overload; |
|
This item has no description. |
procedure SetDeleteVector2(const APath: string; const AValue, ADefaultValue: TVector2); overload; |
|
This item has no description. |
function GetVector3(const APath: string; const ADefaultValue: TVector3): TVector3; overload; |
|
This item has no description. |
function GetVector3(const APath: string): TVector3; overload; |
|
This item has no description. |
procedure SetVector3(const APath: string; const AValue: TVector3); overload; |
|
This item has no description. |
procedure SetDeleteVector3(const APath: string; const AValue, ADefaultValue: TVector3); overload; |
|
This item has no description. |
function GetVector4(const APath: string; const ADefaultValue: TVector4): TVector4; overload; |
|
This item has no description. |
function GetVector4(const APath: string): TVector4; overload; |
|
This item has no description. |
procedure SetVector4(const APath: string; const AValue: TVector4); overload; |
|
This item has no description. |
procedure SetDeleteVector4(const APath: string; const AValue, ADefaultValue: TVector4); overload; |
|
This item has no description. |
function GetValue(const APath: string; const ADefaultValue: TVector2): TVector2; overload; deprecated 'use GetVector2'; |
|
Warning: this symbol is deprecated: use GetVector2 This item has no description. |
procedure SetValue(const APath: string; const AValue: TVector2); overload; deprecated 'use SetVector2'; |
|
Warning: this symbol is deprecated: use SetVector2 This item has no description. |
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector2); overload; deprecated 'use SetDeleteVector2'; |
|
Warning: this symbol is deprecated: use SetDeleteVector2 This item has no description. |
function GetValue(const APath: string; const ADefaultValue: TVector3): TVector3; overload; deprecated 'use GetVector3'; |
|
Warning: this symbol is deprecated: use GetVector3 This item has no description. |
procedure SetValue(const APath: string; const AValue: TVector3); overload; deprecated 'use SetVector3'; |
|
Warning: this symbol is deprecated: use SetVector3 This item has no description. |
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector3); overload; deprecated 'use SetDeleteVector3'; |
|
Warning: this symbol is deprecated: use SetDeleteVector3 This item has no description. |
function GetValue(const APath: string; const ADefaultValue: TVector4): TVector4; overload; deprecated 'use GetVector4'; |
|
Warning: this symbol is deprecated: use GetVector4 This item has no description. |
procedure SetValue(const APath: string; const AValue: TVector4); overload; deprecated 'use SetVector4'; |
|
Warning: this symbol is deprecated: use SetVector4 This item has no description. |
procedure SetDeleteValue(const APath: string; const AValue, ADefaultValue: TVector4); overload; deprecated 'use SetDeleteVector4'; |
|
Warning: this symbol is deprecated: use SetDeleteVector4 This item has no description. |
function GetColorRGB(const APath: string; const ADefaultColor: TCastleColorRGB): TCastleColorRGB; overload; |
|
Colors reading/writing to config file. This is very similar to 3D / 4D vector reading/writing to config file, however
They should be expressed in XML like <myColor red="1" green="0.5" blue="0.25" alpha="1" /> <myColorRGB red="1" green="0.5" blue="0.25" />
or as hex colors (see HexToColor) like <myColor hex="ff804011" /> <myColorRGB hex="ff8040" />
You can read such colors by Color := GetColor('example/path/to/myColor', Black); ColorRGB := GetColorRGB('example/path/to/myColorRGB', BlackRGB);
|
function GetColorRGB(const APath: string): TCastleColorRGB; overload; |
|
This item has no description. |
procedure SetColorRGB(const APath: string; const AColor: TCastleColorRGB); overload; |
|
This item has no description. |
procedure SetDeleteColorRGB(const APath: string; const AColor, ADefaultColor: TCastleColorRGB); overload; |
|
This item has no description. |
function GetColor(const APath: string; const ADefaultColor: TCastleColor): TCastleColor; overload; |
|
This item has no description. |
function GetColor(const APath: string): TCastleColor; overload; |
|
This item has no description. |
procedure SetColor(const APath: string; const AColor: TCastleColor); overload; |
|
This item has no description. |
procedure SetDeleteColor(const APath: string; const AColor, ADefaultColor: TCastleColor); overload; |
|
This item has no description. |
function PathElement(const APath: string; const RaiseExceptionWhenMissing: boolean = false): TDOMElement; |
|
For a given path, return corresponding DOM element of XML tree. This is useful if you want to mix XMLConfig style operations on the file and then use some real DOM functions to more directly operate/read on XML document. Note that for paths that you pass to various SetValue / SetColor / SetFloat / SetVector versions, the last path component is the attribute name. You do not pass this here. Path passed here should end with the name of final element. Path passed here may but doesn't have to be terminated by a final slash. In fact, for now the path is just splitted using slash character as a separator, so a path like If there is no such element: when RaiseExceptionWhenMissing= Remember that XMLConfig idea of XML document is limited. That's intentional (XMLConfig is supposed to offer only a simple limited XML access), and this means that some XML trees may confuse XMLConfig. For example, if there are two elements with the same TagName as a children of the same element: XMLConfig will (probably ?) just always ignore the second one. Which means that if you use this method to change some XML content, you should be careful when accessing this content from regular XMLConfig GetValue / SetValue methods. Note that if you modify the DOM contents this way, you must manually call MarkModified afterwards, to make sure it will get saved later. |
function MakePathElement(const APath: string): TDOMElement; |
|
Similar to PathElement, but creates the necessary elements along the way as needed. |
function PathChildren(const APath: string; const ChildName: string): TDOMNodeList; deprecated 'use PathChildrenIterator'; |
|
Warning: this symbol is deprecated: use PathChildrenIterator For a given path, return corresponding children elements of a given DOM element of XML tree. For example, you have an XML like this: <?xml version="1.0" encoding="UTF-8"?> <CONFIG> <game_configuration> <locations> <location name="location_1st">...</location> <location name="location_2nd">...</location> </locations> </game_configuration> </CONFIG>
You could use Raises exception if element indicated by APath does not exist. (But it is OK if it is empty.) Never returns |
function PathChildrenIterator(const APath: string; const ChildName: string): TXMLElementIterator; |
|
For a given path, return iterator for elements of a given name. For example, assume you have an XML like this: <?xml version="1.0" encoding="UTF-8"?> <CONFIG> <game_configuration> <locations> <location name="location_1st">...</location> <location name="location_2nd">...</location> </locations> </game_configuration> </CONFIG>
You can process it like this: var I: TXMLElementIterator; begin I := PathChildrenIterator('game_configuration/locations', 'location'); try while I.GetNext do begin // ... here goes your code to process I.Current ... end; finally FreeAndNil(I) end; end;
Raises exception if element indicated by APath does not exist. (But it is OK if it is empty.) Never returns |
function GetUrl(const APath: string; const EmptyIfNoAttribute: boolean = false): string; |
|
Read an URL from an XML attribute. The attribute in an XML file may be an absolute or relative URL, (we will look at own TXMLConfig.FileName directory to resolve relative URLs). The returned URL is always an absolute URL. If EmptyIfNoAttribute, then this will just set URL to '' if appropriate XML attribute not found. Otherwise (when EmptyIfNoAttribute = Exceptions raised
|
procedure NotModified; |
|
This item has no description. |
procedure MarkModified; |
|
This item has no description. |
function Document: TDOMDocument; |
|
This item has no description. |
procedure AddLoadListener(const Listener: TCastleConfigEvent); |
|
Listeners, automatically called at the Load or Save calls. If the config file is already loaded when you call |
procedure AddSaveListener(const Listener: TCastleConfigEvent); |
|
This item has no description. |
procedure RemoveLoadListener(const Listener: TCastleConfigEvent); |
|
This item has no description. |
procedure RemoveSaveListener(const Listener: TCastleConfigEvent); |
|
This item has no description. |
procedure Load; overload; |
|
Load the current persistent data (user preferences, savegames etc.). All these methods call the listeners (from AddLoadListener). All these methods update the IsLoaded property and the URL property. All these methods are secured to never raise exception in case of a currupted config file – in this case, they silently load an empty config (but keep the new URL, so that following Save call with overwrite the config location with a good save.) Never call the ancestor load / save methods, like TXMLConfig.LoadFromStream and TXMLConfig.SaveToStream, to be on the safe side. Use the methods below to load / save user config.
|
procedure Load(const AUrl: String); overload; |
|
This item has no description. |
procedure Load(const Stream: TStream; const PretendUrl: String); overload; |
|
This item has no description. |
procedure LoadFromString(const Data: string; const PretendUrl: String); |
|
This item has no description. |
procedure Save; overload; |
|
Save the user persistent configuration. Calls all the listeners (registered by AddSaveListener).
|
procedure Save(const Stream: TStream); overload; |
|
This item has no description. |
function SaveToString: string; |
|
This item has no description. |
Properties
property IsLoaded: boolean read FLoaded; |
|
This item has no description. |
Generated by PasDoc 0.16.0-snapshot.