New MyChoices module released to make handling app settings a breeze for developers

Graeme Shrimpton has released a new module, MyChoices, mentioned on the June fireside chat for developers, with the goal of making it much easier for them to load and save their application’s choices (or settings). It deals with the two problems a developer faces – correctly handling where those choices are stored on user machines, and parsing the file that contains them.

The first problem is the file location and how to access it both for reading, and for writing – and the two are slightly different. There are a basic set of rules on how to do this, which a developer has to adhere to if they want their application to do things correctly. MyChoices handles this for the developer, by way of a SWI call to open the file, with pointers to the application name and the file name passed to it; in return the application receives a file handle, which it subsequently uses to read and write choices to the file.

The second problem is slightly more involved. There is no mandated file format for an application’s choices but, depending on the application, there could be just a single item that could be set by the user, or there could be a huge number, or anything between – but the more there is, the more work the program has to do to read them all in.

Graeme’s module makes this easy, by providing calls to read any given setting from the file, by calling them with a pointer to the name of the setting and a pointer to where the result should be stored – and even a default value, so that if the name isn’t found in the file, the default is used (and could be subsequently written to the choices). And, conversely, there are calls to write values to the choices.

The module can handle individual choices as strings, blocks of memory, and integer and floating point values, with a custom format used for the latter that allows them to be interchangeable, which means you can save them in one format (for example as FPA/FPE 32-bit) and read them in another (such as VFP 64-bit) and they will be converted on the fly by the module, with no change necessary to the choices file itself.

Related posts