First of all, memory created by MemHandleNew is released between sessions, so you have no benefit by saving the handle. You can use DmHandleNew, but it would create a lot of coding to insure that memory is released. Rather try to save the "QuestionAnswers" in the same record. Also DmNewRecord will not necessarily return a record with the same Index number that you request, so you have to adjust for that. There might still be other errors, but these were just obvious. LionScribe
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of meg Sent: Saturday, August 30, 2003 8:01 PM To: Palm Developer Forum Subject: database storage I'm concerned about some of my code - I don't know how to figure out if it is working correctly. I have a structure that includes a mem handle and I'm not sure how exactly DMWrite works and whether it copies the data from the mem handle or whether I should be grabbing the data out of the handle before calling DmWrite.... Would someone please let me know 1) if this code should assumedly work and 2) how I might be able to browse a database and see if it actually is storing what i think it is? thanks ******************************code**************************** typedef struct { MemHandle QuestionAnswers; UInt8 sessionFinished; } packed_question_type; /*-------------------------------------------------------------------------- ----------------------------------------------------------- Function: SaveAnswersToDatabase Desccription: saves answers from current session to database Parameters: index for current session's record Return: error code if necessary, otherwise 0 ---------------------------------------------------------------------------- ---------------------------------------------------------*/ Err SaveAnswersToDatabase(UInt16 index) { MemHandle h; MemPtr p; Err error; //allocate memory for the packed question's string packedQuestion.QuestionAnswers = MemHandleNew(1); //store whether the session was completed packedQuestion.sessionFinished=theQuestion.sessionFinished; //pack question for storage PackQuestion(theQuestion); //open questions database error=OpenQuestionsDatabase(); //grab a handle to a new record h = DmNewRecord(questionDatabaseRef, &index, sizeof(packedQuestion)); //if handle was aquired sucesfully if (h) { //lock handle and grab pointer p = MemHandleLock(h); error = DmWrite(p, 0, &packedQuestion, sizeof(packedQuestion)); //unlock the handle MemPtrUnlock(p); //release record and set dirty bit DmReleaseRecord(questionDatabaseRef,index,true); }//if (h) //close questions database error = CloseQuestionsDatabase(); //free memory used by packed question MemHandleFree(packedQuestion.QuestionAnswers); return error; }//SaveAnswersToDatabase -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
