Do you maintain the prefs version information?  If you do, then
you can check the version of the pref you retrieve against the
higest your program recognizes and have it fill in appropriate
default values for any new fields.

--
-Richard M. Hartman
[EMAIL PROTECTED]

186,000 mi/sec: not just a good idea, it's the LAW!

Gordon, Douglas wrote in message <13703@palm-dev-forum>...
>
>Sometimes I add a new preference option by just adding it to the end of the
>structure so that when I read in the preferences, all the existing ones
will
>be in the correct locations. I also generally want the new fields to
>initially be zero. So this is what I was doing:
>
> t_PrefsSize = sizeof(W_PREFS);
> MemSet(&w_Prefs, sizeof(W_PREFS), 0);
> s_PrefVer = PrefGetAppPreferences(GPID_CREATOR, 0, &w_Prefs,
>&t_PrefsSize, true);
>
>In a recent case, I added a new short int field to the structure. The
>initial value of t_PrefsSize was 52; after the GetAppPreferences call the
>first time after "upgrading" from the previous version, t_PrefsSize was now
>set to 50, which was as expected. HOWEVER, the contents of the short int
>field that had initially been zeroed by the MemSet call actually contained
>garbage after the GetPreferences call. In other words, even though the
>function knew that the current saved preferences were shorter than the size
>that I passed in and it returned the actual current size, it actually wrote
>to memory for the full extent of the passed-in size! This seems a bit
>strange, to return a size of 50, but to actually have written 52 bytes.
>
>I got around this behavior something like this:
>
> t_PrefsSize = sizeof(W_PREFS);
> s_PrefVer = PrefGetAppPreferences(GPID_CREATOR, 0, &w_Prefs,
>&t_PrefsSize, true);
> // Zero any new preference fields
> if (t_PrefsSize < sizeof(W_PREFS)) {
> MemSet(((char *) &w_Prefs) + t_PrefsSize, sizeof(W_PREFS) -
>t_PrefsSize, 0);
>
>Kludgey IMO, but it works!
>
>  Doug Gordon
>  GHCS Software
>
>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to