Jeff,

   Thanks for the idea to check after the write.  My problem was that I had
removed code in the write state routines that had used DmGetRecord if there
was already a record in the database at my index (and DmNewRecord if there
was not).  I incorrectly interpreted the description of DmNewRecord to put
the record at the specified index to mean OVERWRITE the record at the
specified index.  So what was happening was that the record at index zero
kept getting pushed to index one when I thought I was overwriting the record
at index zero.  Your suggestion to use unsigned char * exposed that, since
my first field is a string, and I recognized the value.

   I now get the number of records in the database, and use DmGetRecord (to
overwrite an existing record) or DmNewRecord (to create the first record at
the index).  This is working fine, even with the struct DealState * cast.

Al
----- Original Message ----- 
From: "Jeff Ishaq" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Wednesday, May 28, 2003 11:15 AM
Subject: Re: Use of DmQueryRecord function


> At 09:46 AM 5/28/2003 -0400, you wrote:
> >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/
>



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to