static Err ReadDealStateFromDB() { Err err = errNone; MemHandle recordHandle; UInt16 index = gameState.LastDealRecord; // Always record 1 until implement Undo/Redo struct DealState *dState;
recordHandle = DmQueryRecord(gameDB, index); if (! recordHandle) err = DmGetLastErr(); else { dState = (struct DealState *)MemHandleLock(recordHandle); MemMove(&dealState, dState, sizeof(dealState)); MemHandleUnlock(recordHandle); } ErrFatalDisplayIf(err != errNone, "Can't read deal state from database"); return err; }
I have similar code to successfully write and read a global structure gameState variable at index 0. However, my dealState structure is totally bogus (there are no runtime errors, i.e., err is errNone).
Your code looks fine to me. I would suspect that something is going wrong when you try to WRITE record 1.
I would put some test code in IMMEDIATELY after you've written record 1 and committed it back to the database with DmReleaseRecord()... e.g., do the same DmQueryRecord() / MemHandleLock() that you have posted here, and use your debugger to view the memory of the resulting pointer -- is it being written as expected?
Sometimes it's best to cast the locked handle to a unsigned char *, rather than a structure type *, to isolate the problem and minimize outside errors.
-Jeff Ishaq
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
