Greetings all,

   I'm experimenting w/ the preference structure by trying to make a
simple app with a persistent text field - that is, the contents should
remain when you close and re-open the program.  Running the program on
POSE (w/o debugging), everything works fine the first time the program is
opened and closed.  When it is re-opened (and tries to refresh the text
content), I get a low memory read in my MainFormInit function below
somewhere in the FldInsert call.  Could someone tell me what obvious rule
I'm breaking?  Do I need to lock the text field before I can call the
Insert function? 

   
 The basic code:
 
typedef struct 
        {
        char lastFieldString[15];
        } TestPreferenceType;

static TestPreferenceType prefs;

static void MainFormInit(FormPtr frmP)  {
        FieldPtr fldP;
        char myBuf[20];
        
        fldP = GetObjectPtr(TestMainTextField);   // the text field
        FldDelete(fldP, 0, FldGetTextLength(fldP));
        StrCopy(myBuf, prefs.lastFieldString);
        FldInsert(fldP, myBuf, StrLen(prefs.lastFieldString));
}

static Err AppStart(void)  {
        if (PrefGetAppPreferences(appFileCreator, appPrefID, &prefs, &prefsSize, true) 
!= 
                noPreferenceFound) {}
}

static void AppStop(void)  {
        FieldPtr fldP;
        Handle textH;
        CharPtr textP;

        // Write the saved preferences / saved-state information.  This data 
        // will be backed up during a HotSync.
        fldP = GetObjectPtr(TestMainTextField);
        textH = FldGetTextHandle(fldP);
        textP = MemHandleLock(textH);
        StrCopy(prefs.lastFieldString, textP);
        MemHandleUnlock(textH);

        PrefSetAppPreferences (appFileCreator, appPrefID, appPrefVersionNum, 
                &prefs, sizeof (prefs), true);
}

Reply via email to