Save program settings ( file or registry ?)

TWELVE

Active Member
Licensed User
Hello,

i've got a question regarding how i can save my app's settings/preferences.

I want so save my app/user settings to somewhere ( file, registry), so i can read them after program start to save the user from doing the settings all the time over and over.

1. Do you need to save settings in your programs.. ?

2. How do you do this..?

2. has anyone a piece of code - or possibly a lib - ready that is handling the settings ( create/read/save)..?

i personally tend not to use the registry, for certain reasons, but if one has already something similar in place, i could be persuaded :))


cheers

TWELVE
 

klaus

Expert
Licensed User
Longtime User
Hello TWELVE,

I save the values of the setting variables in a simple text file when leaving the program. And load this file at startup and set the settings.

I do this in all my programs.
You can have a look in the Wine Cellar Manager program.
http://www.b4x.com/forum/share-your-creations/2136-wine-cellar-manager.html
The routines are SaveInit and LoadInit where I save the Language index, last file used and the table column widths. But anyway there is really nothing special in there.

You can also have a look in alfcen's B4ppctemplate.
http://www.b4x.com/forum/share-your-creations/1738-basic4ppc-program-template.html

Best regards
 

specci48

Well-Known Member
Licensed User
Longtime User

TWELVE

Active Member
Licensed User
I save the values of the setting variables in a simple text file when leaving the program. And load this file at startup and set the settings.

This was also my plan.i looked into your code, the way you do this is just plain saving of the values.I thought about something like this here:

COMPort = COM8
Server = "a server"

This is not that hard to program, but it is harder than it appears to be..:)

Is some advanced string processing because you don't know where the equals are and the parameter name also could contain some spaces.

Hello Twelve,

maXin has provided a "db2000 - INI" dll in the italian forum

Thx..i will have a look at this stuff.

For my own programs I often use just an internal (invisible) table to store the settings/preferences because with this you don't have to code some extra lines for the file handling.

How does this work if you exit the program, where is the table being stored..?


cheers

TWELVE
 

WZSun

Member
Licensed User
Longtime User
Hi,
Do take note that ""db2000 - INI" dll" is not compatible with the Beta 2.62 if compiled with optimised option enabled.. as it reported an error.. even when running from IDE mode.
 

Cableguy

Expert
Licensed User
Longtime User
This was also my plan.i looked into your code, the way you do this is just plain saving of the values.I thought about something like this here:

COMPort = COM8
Server = "a server"

This is not that hard to program, but it is harder than it appears to be..:)

Is some advanced string processing because you don't know where the equals are and the parameter name also could contain some spaces.

TWELVE

Since the Format of the parameters are setted BY YOU, then, you can use that to make sure the settings are "Original" and read the important lines and the trimm them so that only the needed info is kept...

Here's an aboandoned project of mine, but in wich, a full basical ini file reading/wtng is implemented...
 

Attachments

  • sample.zip
    21 KB · Views: 275

specci48

Well-Known Member
Licensed User
Longtime User
How does this work if you exit the program, where is the table being stored..?

Before exiting the program I'll copy every data to be stored into the table. After that I'll just use SaveCSV to export the data to the current folder of the program. As the filename I'll use something like AppPath & "\MyProgram.cfg"


specci48
 

TWELVE

Active Member
Licensed User
Cableguy said:
Here's an aboandoned project of mine, but in wich, a full basical ini file reading/wtng is implemented...

Thx a lot..i will have a look into your code and see what's usuable for my project..!



specci48 said:
Before exiting the program I'll copy every data to be stored into the table. After that I'll just use SaveCSV to export the data

That's pretty nice and easy at the same time.I didn't take notice of the table.control because i didn't have a use for it.

Since cableguy recommended to use the table.control for prefs file manipulation, this little table thingy appears to be very useful.

The table.control solution is easy and done very quickly, but the resulting cfg file is not the style i was thinking of.

I wrote now a routine, which removes all spaces at the start and end of each line and returns config key and it's value.That's working with an existing file from the windows version of my application, and this was what i was looking for primarily.


Unfortunately now i've got some issues in saving the prefs file.I believed i could just replace a single line within the existing file, but that doesn't work that easy.I opened up a new thread for that, but answers to this were also welcomed here.

cheers

TWELVE
 
Last edited:
Top