How is MyPrefDB defined? Am Freitag, 3. September 2004 17:51 schrieb [EMAIL PROTECTED]: > I am still having trouble restoring the preferences. > > I saved the preferences as so: > MyPrefDB *prefP = (MyDB *) MemPtrNew (sizeof(MyPrefDB)); > StrCopy(prefP->data, "MyData") > PrefSetAppPreferences(kCreator, 0, 1, &prefP, sizeof(MyPrefDB), true); > MemPtrFree(prefP); > > and it worked fine. But when I try retrieve it, and initialize it back to > the textfield on my form, its giving me an error: > > UInt16 PrefSize = sizeof(MyPrefDB); > MyPrefDB *prefP = (MyPrefDB *) MemPtrNew (sizeof(MyPrefDB)); > PrefGetAppPreferences(kCreator, 0, prefP, &PrefSize, true); > StrCopy(MyChar, prefP->data); //MyChar is a character[] > MemPtrFree(prefP); > > ***But when I tried to do this: > StrCopy(MyChar, "test"); > instead of, > StrCopy(MyChar, prefP->data); > The "test" string was initialized with no problem. > > I think that I am reading from the Ptr of the MyPrefDB the wrong > way...please help! > > In a message dated 9/3/2004 3:27:41 AM Eastern Daylight Time, "Helmut A. Bender" <[EMAIL PROTECTED]> writes: > >Am Freitag, 3. September 2004 00:36 schrieb Tim Kostka: > >> What you are doing is saving the *pointer* to the preference data, which > >> is of course not what you want as that pointer is invalid as soon as you > >> call MemPtrFree. �To save the database, you would do the following: > >> > >> MyPrefDB *prefP = (MyDB *) MemPtrNew (sizeof(MyPrefDB)); > >> // populate data here before you save it > >> PrefSetAppPreferences(kCreator, 0, 1, &prefP, sizeof(MyPrefDB), true); > >> MemPtrFree(prefP); > > > >nearly right, but now you set the value of the pointer with the size of > > the MyPrefDB. It shoud be > > > >PrefSetAppPreferences(kCreator, 0, 1, prefP, sizeof(MyPrefDB), true); > > > >> and to restore: > >> > >> UInt16 PrefSize = sizeof(MyPrefDB); > >> MyPrefDB *prefP = (MyPrefDB *) MemPtrNew (sizeof(MyPrefDB)); > >> PrefGetAppPreferences(kCreator, 0, &prefP, &PrefSize, true); > > > >Here, too, prefP is already the pointer to the buffer, so write > > > >PrefGetAppPreferences(kCreator, 0, prefP, &PrefSize, true); > > > >as in the original mail. > > > >> when you are done accesing the data, use MemPtrFree to release it. > >> > >> Also, the call PrefGetAppPreferences will return values which will let > >> you know what's going wrong. �If there's no preference stored, then > >> it'll tell you. �It also returns the size of the preference data. �Read > >> the documentation on that function if you want a better understanding of > >> what it tells you. > >> > >> Hope this helps, and hope I didn't make any typos. �:) > >> -- > >> Tim Kostka > >> > >> > >> > >> <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >> > >> > Problem: How do I retrieve a large struct Preference which was stored > >> > by using MemPtrNew?? > >> > > >> > I was able to set the preference in my StopApp function this way: > >> > > >> > MyPrefDB *prefP = (MyDB *) MemPtrNew (sizeof(MyPrefDB)); > >> > PrefSetAppPreferences(kCreator, 0, 1, prefP, sizeof(prefP), true); > >> > MemPtrFree(prefP); > >> > > >> > In my startApp function, I try to retrieve it using this code, but its > >> > giving me an error: > >> > > >> > UInt16 PrefSize = sizeof(MyPrefDB); > >> > MyPrefDB *prefP = (MyPrefDB *) MemPtrNew (sizeof(MyPrefDB)); > >> > PrefGetAppPreferences(kCreator, 0, prefP, &PrefSize, true); > >> > MemPtrFree(prefP); > >> > > >> > Am I doing this right?? Any help in this matter is greatly > >> > appreciated..Thanks in advance. > > > >-- > >Mit freundlichen Gr��en > >Helmut A. Bender > >Helmut Bender GmbH > > > >-- > >For information on using the Palm Developer Forums, or to unsubscribe, > > please see http://www.palmos.com/dev/support/forums/
-- Mit freundlichen Gr��en Helmut A. Bender Helmut Bender GmbH -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
