Configuration/preferences file

  1. 3 years ago

    How do you create a configuration/preferences file?

  2. Kem T

    22 Jan 2014 Pre-Release Testers, Xojo Pro New York

    The short answer is, however you'd like. There is no hard and fast rule on this. I use a very simple text format of key=value (I hex-encode value where needed), others use XML or Plist, still others use a SQLiteDatabase.

    It's really up to you.

  3. 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?

    Sam

  4. Roger C

    22 Jan 2014 Lewis Center, OH

    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

  5. Roger C

    22 Jan 2014 Lewis Center, OH

    Chiming in on your 2nd question, if you're just starting, I would recommend just using a simple Binary File. Your Prefs does not HAVE to be any kind of special file. See the Xojo docs on writing to a binaryStream and just write your values to a simple file.

  6. Paul L

    22 Jan 2014 Xojo Inc http://developer.xojo.com

    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.

    http://docs.xojo.com/index.php/Videos#Webinars

  7. James D

    22 Jan 2014 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    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.

  8. Dave S

    22 Jan 2014 San Diego, California USA

    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

  9. Mike C

    22 Jan 2014 Pre-Release Testers, Xojo Pro North Carolina (USA)

    Please do so Dave that would be very helpful. Thank you again.

  10. Massimo V

    23 Jan 2014 Pre-Release Testers, Xojo Pro Europe (Germany, Würzburg)

    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.

  11. Garry P

    23 Jan 2014 Pre-Release Testers Europe (Torquay, UK)

    I tend to use a SQLite database. Works cross-platform out of the box.

  12. Dave S

    23 Jan 2014 San Diego, California USA

    link text

    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....

  13. (downloaded)
    Dave, thank you. I am going to check this out.

  14. Richard D

    23 Jan 2014 Pre-Release Testers Europe (UK, London)

    @Garry P I tend to use a SQLite database. Works cross-platform out of the box.

    same here.. i keep my config and login info in sqlite file

  15. Dale A

    23 Jan 2014 San Diego, California, USA

    @Garry P I tend to use a SQLite database. Works cross-platform out of the box.

    I do this also if my application will require a database anyway. Otherwise I tend to use a binary file.

  16. James D

    23 Jan 2014 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    @Garry P I tend to use a SQLite database. Works cross-platform out of the box.

    Yes but it is not so easy to just open it up and make a change. Or even worse as a use at the end of the phone to tell you what the values are ;-)

  17. Oliver S

    23 Jan 2014 North Yorkshire, United Kingdo...

    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!

  18. Oliver S

    23 Jan 2014 North Yorkshire, United Kingdo...

    @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.

    Thanks

  19. James D

    23 Jan 2014 Pre-Release Testers, Xojo Pro Europe (Switzerland)

    I keep getting an error message if I try to post a link directly to a zip file, so here is a blog link instead. My Preferences project .

    Bug reports, tips etc are most welcome, as I'm just starting out with XOJO

  20. Dave S

    23 Jan 2014 San Diego, California USA

    Windows dropped support for INI files in preference to the awful REGISTRY years and years ago.

    my class "mimics" INI in the fact that is has sections, keys and values.... and stores things in plain text

  21. Newer ›

or Sign Up to reply!