As previously reported (see "Treo 650 (GSM) crashing on delete
record!"), the current 650 - and T5 as reported by others - has a bug
in the DmDeleteRecord function. This is a problem if an application
has a conduit dependent on records being flagged as deleted, otherwise
DmRemoveRecord can and should be used in place of DmDeleteRecord.
Following is a workaround for the defect in the Treo 650 and T5. I
have tested with the 650 simulator and done
some testing with previous OS versions and all seems to work as it
should. In my case I only need to replace the DmDeleteRecord call in
one application function (my deleteRecord shown below).
static Err deleteRecordWorkAround(DmOpenRef dbP, UInt16 index) {
UInt16 attr;
MemHandle oldH;
// Set localChunkID of the record entry to NULL as per
DmDeleteRecord docs.
Err err = DmAttachRecord(dbP, &index, NULL, &oldH);
if(!err) {
if(oldH) {
// free the chunk that had belonged to the record.
MemHandleFree(oldH);
}
DmRecordInfo(dbP, index, &attr, NULL, NULL);
attr |= dmRecAttrDelete|dmRecAttrDirty;
DmSetRecordInfo(dbP, index, &attr, NULL);
}
return err;
}
/**
* Delete or archive a record.
* @param dbP the database reference.
* @param index current sort index of the record.
* @param archive if true archive the record else delete it.
*/
void deleteRecord(DmOpenRef dbP, UInt16 index, Boolean archive) {
if (archive)
DmArchiveRecord(dbP, index);
else
// DmDeleteRecord(dbP, index);
deleteRecordWorkAround(dbP, index);
// Deleted records are stored at the end of the database.
DmMoveRecord(dbP, index, DmNumRecords(dbP));
}
Thanks to Chris Faherty for the workaround approach.
Ralph
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/