Did you draw first?  I know there are some problems when designating text
with some form objects before they are drawn.  Just a thought.  Probably too
many steps -- I would have to go back to the code, but I don't believe with
FldInsert you would need to copy to a buffer first.  FldInsert should
basically do that for you -- take it out of your string and place it into
the field's allocated memory.

Elia

-----Original Message-----
From: Michael D. McFarland [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 13, 1999 7:39 PM
To: Palm Developers List
Subject: problem w/ FldInsert?


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