How do you create a configuration/preferences file?
Thanks, Kem. I'm an absolute beginner at this, learning how to program. Sorry for the very naive, general question. I need to create a configuration/preferences file so that I can save the initial settings for my program. Given my application, how would I use, say, Plist? Is there a good tutorial for it somewhere? Is it Xojo-specific?
I also use a simple binary file for my Prefs. Some like NSUserDefaults or CFPreferences for Mac builds.
Whatever you choose, you should store it in SpecialFolder.ApplicationData. Using SpecialFolder.Preferences, despite its name, can be problematic with later Operating systems
One solution that is pretty simple is to use JSONItem to store values in a Dictionary-like manner. Then you can just save and load this JSON data to a file pretty easily.
For an example of this, check out the Developing a Text Editor webinars. I believe part 2 covers saving preferences.
I use the same preferences class for both user and application settings. It uses simple key-value pairs and it supports the storage and retrieval of the standard data types plus Color and FolderItem. It uses a simple xml file in the background to store key, value and data type.
One problem I've had in the past is developers shipping their settings with product, so I've added a little twist - an overwrite file. If found, then after loading the preferences, it's values will be used to overwrite them and on save, values loaded from the overwrite file and changed will be written back to the overwrite file.
My SVN commit script filters out the overwrite file as do my build scripts.
I normally prefer to use Plist for OS X and XML for Windows.
Since Plist is essentially an XML file, this permits to have very similar files in both platforms.
And XML is nicer when you have to change the format of the file and still keep a good degree of retro-compatibility.
Here it is with a bit of sample code....
Normally you drop this class into your project. and modifiy the 3 methods in the modOPTIONS module depending on the parameters you are loading and saving. It includes overloaded functions to PUT and GET most all XOJO standard datatypes.
I have used this in every project I have written for the past several years....
I use XML. I am not so sure about SQLite or JSON but XML is really easy to debug. I often use messageboxes to display the information saved by an XML to read if everything is how I want it and I can write or modify an XML file in an external text editor, which is also great for debugging!
@Dave S I use a class I wrote years ago the in some respects mimics the old Windows INI file... but works on all platforms...
I'll post a link if anyone is interested
'mimics the old Windows INI file', are you saying that support for INI files has been dropped by Microsoft or something? Or has INI files become an old way of doing things.