At 11:04 AM 02/25/2001 -0800, Ken wrote:
>One minor nit. Once you've called FldSetTextHandle, the field code 
>effectively "owns" the handle. Thus you should avoid messing with the 
>handle following this call, which means that the unlock should happen 
>before you call FldSetTextHandle.

Good suggestion, thanks.  I'm wondering about something else:

I have two fields on a frmDoDialog form being written to from a 
database.  The fields are set to be non-editable, as I am wanting to only 
display the contents.  Problems is this: I can tap the field and 
backspace.  When doing this, PalmOS issues a fatal error from the MemoryMgr.

I thought it was due to something as above, but I'm afraid it's 
different.  I would appreciate some analysis of the problem.

TIA.

My concern are the two lines below, as they are never unlocked in the code:

listStudentName[itemNum] = (Char*)MemHandleLock(MemHandleNew ( StrLen( 
item->name ) + 1 ) );
listGender[itemNum] = (Char*)MemHandleLock(MemHandleNew ( StrLen( 
item->gender ) + 1) );

Here's a larger snippet:

         h = DmGetRecord(gDBstudent, itemNum);
                 /* If the selected item is found */
                 if (h)
                 {
                         /* A packed item must be locked */
                         pitem = MemHandleLock(h);
                         UnPackRecord ( item, pitem );
                         /* Let listName and listGender point to the 
allocated *
                          * memory for the items name and gender number     */
                         listStudentName[itemNum] = 
(Char*)MemHandleLock(MemHandleNew ( StrLen( item->name ) + 1 ) );
                         listGender[itemNum] = 
(Char*)MemHandleLock(MemHandleNew ( StrLen( item->gender ) + 1) );

                         if ( listStudentName[itemNum] && listGender[itemNum]){
                                 StrCopy ( listStudentName[itemNum], 
item->name );
                                 StrCopy ( listGender[itemNum], item->gender );
                         }

                         name = listStudentName[itemNum];
                         gender = listGender[itemNum];
                         /* Load and initialize frmShowStudent */
                         form = FrmInitForm(frmShowStudent);
                         FrmSetActiveForm(form);
                         /* Let FldPtr point to the field "fldStudent" in 
frmShowStudent*/
                         fldPtr = FrmGetObjectPtr(form, 
FrmGetObjectIndex(form, fldStudent));
                         FldSetTextPtr(fldPtr, name);
                         /* Let FldPtr point to the field "fldGender" 
(noneditable) in frmView */
                         fldPtr = FrmGetObjectPtr(form, 
FrmGetObjectIndex(form, fldGender));
                         FldSetTextPtr(fldPtr, gender);

                         buttonTapped = FrmDoDialog(form);
                         /* Determine which button is tapped, and do 
whatever the user wants */
                         if ( buttonTapped == cmdClose)
                         {
                                 /* When the user taps the OK button, 
release the record */
                                 DmReleaseRecord(gDBstudent, itemNum, false);
                                 MemHandleUnlock(h);
                         }
                         else if (buttonTapped == cmdDeleteItem )
                         {
                                 if ( FrmCustomAlert(alDelete, name, NULL, 
NULL) == 0 )
                                 {
                                         DmRemoveRecord(gDBstudent, itemNum);
                                 }
                                 else
                                 {
                                         DmReleaseRecord(gDBstudent, 
itemNum, false);
                                         MemHandleUnlock(h);
                                 }
                         }
                 }
         }


[rb}

http://www.randybrown.net


-- 
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