Chrix Bell wrote:
I make the codes below, I want to insert a new record into a database.
But the simulator just stopped at the last line of this routine. At this
moment, if I step over or force run,
the simulator will crash.
Could anyone help me about this?
void DBNewRecord(DmOpenRef db, DBRecord *record, UInt16 *indexP)
When you call this function, are you passing a DmOpenRef that is
to a database which is open read-write? Did you use dmModeReadWrite?
{
UInt16 index;
MemHandle newRecordH;
DBRecord *newRecordP;
index = DmFindSortPosition(db, &record, NULL,
(DmComparF *) CompareDBRecords, NULL);
This may not be the problem, but I always suggest that you use no
cast on callback functions. If the function is the wrong type,
you need the compiler to tell you. Casting turns off this error
checking, and the error checking can be very helpful sometimes.
newRecordH = DmNewRecord(db, &index, GetRecordSize(record));
newRecordP = MemHandleLock(newRecordH);
DmWrite(newRecordP, 0, &record, GetRecordSize(record));
Do you really have "&record"? If so, you are getting a pointer
to the second argument passed into your DBNewRecord() function.
Since this argument is a pointer value that exists on the stack,
you are passing an address on the stack to DmWrite(), and then
DmWrite() will read from the stack instead of from the record.
This is almost certainly not what you want.
MemHandleUnlock(newRecordH);
DmReleaseRecord(db, index, true);
*indexP =index ;
DmCloseDatabase(gLibDB);
It seems like this should be "DmCloseDatabase (db);" rather than
"DmCloseDatabase(gLibDB);".
Actually, I don't understand why you would open the database before
you call the function and then close it at the end of the function.
It seems more logical to either open AND close it in the same
function or to do neither.
}
Hope that helps.
- Logan
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/