Continuing our discussion on how to overwrite an existing record
more-or-less atomically...
"John J. Corelli" <[EMAIL PROTECTED]> wrote in message
news:52935@palm-dev-forum...
> // following archive procedure for updating a
record
> with new data.
> resultRec = DmNewRecord(CrewResDB, &index, sizeof(ResultType));
You want to use DmNewHandle. DmNewRecord does the attach for you (but
doesn't replace an existing record).
>
> // Lock down the block containing the new record.
> p = MemHandleLock(resultRec);
>
> // Write out the entire result record - title and all.
> error = DmWrite(p, index, &Result, sizeof(Result) );
>
> DmAttachRecord(CrewResDB, &index, resultRec, oldHP);
>
> MemHandleUnlock(resultRec);
>
> // old record
> resultRec = DmGetRecord(CrewResDB, CurrResRecord);
Unlock before attaching rather than after. Do the DmGetRecord (actually
DmQueryRecord would be more appropriate here) before attaching, so you can
tell DmAttachRecord which record it's replacing. Obviously, you don't want
to use the same variable (resultRec) to store the old record and the new
one.
> MemHandleFree(resultRec); //wasn't sure what handle to pass this
function...
You want to pass it the handle returned via the last parameter to
DmAttachRecord.
> Also, Danny's post referenced the source code for the PIM apps in the
> SDK...I have the SDK, but where is the source code for the examples?
It should be in an Examples folder somewhere in there. Look around a bit -
you should see "Memo.c", etc.
Here's a fixed version of your code (untested, without error checks, etc):
newH = DmNewHandle(CrewResDB, sizeof(ResultType));
p = MemHandleLock(newH);
error = DmWrite(p, index, &Result, sizeof(Result) );
MemHandleUnlock(newH);
oldH = DmQueryRecord(CrewResDB, CurrResRecord);
index = CurrResRecord;
DmAttachRecord(CrewResDB, &index, newH, &oldH);
MemHandleFree(oldH); // now contains the replaced record
--
Danny
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/