Greetings,
I finally managed to figure this one out, so I'll post my solution to the list for future reference.
I have been programming a latin dictionary as my first major Palm program, and since I have a Mac iBook to program on (and an old Visor to deploy on) I haven't been able to do any testing on a Tungsten device (or any other device with OS5). However, a user has written me back to tell me that he gets the following error when running my program on his Tungsten: "Field68K.c, Line:253, Form object (field) not found". He then has to reset his Palm.
I ran the Palm Simulator under VirtualPC (a painful process) and discovered that the debug roms give an additional error, referencing a bad pointer. I discovered finally that the cause was due to FormObject pointers going out of scope upon discarding a stack frame on return from a function call (at least that's my guess). For instance, I had the following code:
void Lookup() {
UInt16 category = dmAllCategories;
Char* word = (Char*) GetInput();
ClearResults();
... etc
}// Get the character string entered in the "Lookup" field
Char* GetInput() {
FieldType* entryField = (FieldType*) FrmGetObjectPtr(FrmGetActiveForm(), FrmGetObjectIndex(FrmGetActiveForm(), EntryField));
Char* word = FldGetTextPtr(entryField);
return word;
}
I never had any problems under the 68K Palms, but apparently there's something finicky in the 68K emulation on the ARM. The value returned from GetInput() is really a TextPtr to my EntryField's text contents. Upon return from GetInput(), the TextPtr becomes invalid, and any attempt to access the field data results in a "Bad Pointer" error and then the "Field68K.c, Line:253, Form object (field) not found" error. The following code fixes the issue:
void Lookup() {
UInt16 category = dmAllCategories;
UInt16 i, recNum = 0, numResults = 0;
Char word[101]; GetInput(word);
ClearResults();
... etc
}// Get the character string entered in the "Lookup" field
void GetInput(Char* wordOut) {
FieldType* entryField = (FieldType*) FrmGetObjectPtr(FrmGetActiveForm(),
FrmGetObjectIndex(FrmGetActiveForm(), EntryField));
Char* wordIn = FldGetTextPtr(entryField);
StrCopy(wordOut, wordIn);
}Now, no TextPtr is passed back, and voila, no more errors.
-Erik Norvelle
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
