XML Process
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
XML Process
Hi,
What is the normal process in dealing with loading preference files on Application startup.
I am building my first Desktop Applicatin and have come to the stage of needing to setup Preferences which will be stored in a file.
I am right now deciding if I should create this file as an XML File for portability into other systems or do I create my own format... opinions?
If I do decide to go with XML is it normal on application startup to create the XML Tree from the file and keep that in memory so all parts of the Application can use it if needed?
Is this standard practice...
What is the normal process in dealing with loading preference files on Application startup.
I am building my first Desktop Applicatin and have come to the stage of needing to setup Preferences which will be stored in a file.
I am right now deciding if I should create this file as an XML File for portability into other systems or do I create my own format... opinions?
If I do decide to go with XML is it normal on application startup to create the XML Tree from the file and keep that in memory so all parts of the Application can use it if needed?
Is this standard practice...
Re: XML Process
Hi,
This might get you started: http://qery.us/3ea
Feel free to ask questions on the blog.
Kind regards,
Mark
This might get you started: http://qery.us/3ea
Feel free to ask questions on the blog.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: XML Process
There isn't really a "normal" process, you can create your prefs file in whatever format you like. For simple apps, I've just used a text file with one preference per line, like this:
green
10
DaisyMae
My app knows which line means which preference. But lately I've been using stacks to store preferences because of the many storage options they provide. Usually I set a custom property to the preference, which gives me an automatic array and makes it easy to extract any preference I want:
set the cUserName of stack "prefs" to "DaisyMae"
set the cUserAge of stack "prefs" to "10"
put the cUserName of stack "prefs" into tUserName
--etc
I can store anything in custom properties and it is far easier than messing around with XML, which to me is a waste of time for something like this.
Different OSs require different places to store prefs files. You can use the specialFolderPath("preferences") or the application support folder on Macs -- specialFolderPath("asup"). There's a fantastic folder resource on Ken Ray's site, which I consult all the time: http://www.sonsothunder.com/devres/live ... ile010.htm Go back one page for a complete list of invaluable tricks and tips like this one.
green
10
DaisyMae
My app knows which line means which preference. But lately I've been using stacks to store preferences because of the many storage options they provide. Usually I set a custom property to the preference, which gives me an automatic array and makes it easy to extract any preference I want:
set the cUserName of stack "prefs" to "DaisyMae"
set the cUserAge of stack "prefs" to "10"
put the cUserName of stack "prefs" into tUserName
--etc
I can store anything in custom properties and it is far easier than messing around with XML, which to me is a waste of time for something like this.
Different OSs require different places to store prefs files. You can use the specialFolderPath("preferences") or the application support folder on Macs -- specialFolderPath("asup"). There's a fantastic folder resource on Ken Ray's site, which I consult all the time: http://www.sonsothunder.com/devres/live ... ile010.htm Go back one page for a complete list of invaluable tricks and tips like this one.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: XML Process
Hi jacque,
Simon
I'm getting the odd feeling that this says standalones can save themselves? Have I missed something maybe like standalones can't save themselves but it can create a substack that it can save? Maybe not even create but change an additional stack file that gets saved?But lately I've been using stacks to store preferences
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: XML Process
No, standalones can't save themselves or save data to their substacks. The prefs stack I was talking about is a separate stack that is saved as an independent file in the appropriate preferences folder. Regular stacks are just documents and can be saved like any other app's documents.
My scripts typically create a new, blank stack that the user never sees, and save it to disk. This can happen on first launch, the first time you need to save a preference, or any other time:
My scripts typically create a new, blank stack that the user never sees, and save it to disk. This can happen on first launch, the first time you need to save a preference, or any other time:
Code: Select all
on savePref pPref,pValue
put specialFolderPath("asup") & "/MyPrefs.lc" into tPrefsFile
if there is no stack tPrefsFile then
create invisible stack "myPrefs"
set the filename of it to tPrefsFile
save stack "myPrefs"
end if
set the pPref of stack "myPrefs" to pValue
end savePref
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: XML Process
Hi jacque,
So the difference between saving a stack file and saving a text file is that you can use:
as opposed to:
Allowing you to use a custom property rather than line/word/item to select?
I like that... "feels" more accurate.
Simon
So the difference between saving a stack file and saving a text file is that you can use:
Code: Select all
put the pPref of stack "myPrefs" into myLocalVar
Code: Select all
put url "file:myPrefs.txt" into myPrefs
put line 3 of myPrefs into myLocalVar
--or
put item 5 of myPrefs into myLocalVar
I like that... "feels" more accurate.
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: XML Process
Thanks for the advice.
I kind of agree with Jacque that the XML path seems unnecessarily complicated and I do like the method of saving the Prefs to a Stack File and this method
will overcome the scenario of looking for existing entries etc.
I kind of agree with Jacque that the XML path seems unnecessarily complicated and I do like the method of saving the Prefs to a Stack File and this method
will overcome the scenario of looking for existing entries etc.
Re: XML Process
Hi Nakia,
Mine is still a question up there which I'd like to add to.
Can the custom properties by used like objects?
eg
repeat for the number of customKeys of me --nope
or
repeat for each key tKey of the customKeys of me --nah that didn't work
put the number of customProperties of me into tKey --nope
hmmm... Without addressing the customProperty name specifically, (maybe too big a question) what other ways can one work with the whole data set?
Simon
Mine is still a question up there which I'd like to add to.
Can the custom properties by used like objects?
eg
repeat for the number of customKeys of me --nope
or
repeat for each key tKey of the customKeys of me --nah that didn't work
put the number of customProperties of me into tKey --nope
hmmm... Without addressing the customProperty name specifically, (maybe too big a question) what other ways can one work with the whole data set?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: XML Process
You're close simon
the customkeys -- returns a line delimited list
so your first attempt could be written like so.
2nd method
also from your question change the next option to "put the number of lines in the customkeys of me.."
Might also look at custom property sets, and also be aware you can store an array in a custom property also. So you can have your entire prefs settings in an array and put it into a property, then retrieve the whole array intact from the property on the next run.
the customkeys -- returns a line delimited list
so your first attempt could be written like so.
Code: Select all
put the customkeys into tKeys
repeat with i = 1 to the number of lines in tKeys
put line i of tKeys
end repeat
Code: Select all
repeat for each line tLine in the customkeys of stack "timerclock"
put tLine
end repeat
Might also look at custom property sets, and also be aware you can store an array in a custom property also. So you can have your entire prefs settings in an array and put it into a property, then retrieve the whole array intact from the property on the next run.
Re: XML Process
Ha, funny me.
There I was extolling the virtues of using a custom property because it wasn't a chunk expression and the first thing I do is ask how to make it into chunks!
Ha
Simon
There I was extolling the virtues of using a custom property because it wasn't a chunk expression and the first thing I do is ask how to make it into chunks!
Ha
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!