You've pretty much got it. If you follow your code path however, you are unlocking myRecord twice. Each time you unlock a record it decrements the lock count. Since you are doing it twice, you are decrementing the count to a number below zero, thus getting the "Chunk under-locked" error. If DmGetRecord fails, it shouldn't have locked anything, so get rid of the second MemHandleUnlock. You should be doing a DmReleaseRecord when you're done too.


At 09:50 05/08/2003 -0500, you wrote:
Hi all....

This is a bit of a fundamental question here but I think I only barely
grasp how this whole Locking and Unlocking chunks is all about, not
to mention I'm a newbie programmer. :\

I realize you need to set aside a block or "chunk" of memory before
assigning a variable any value but it's the how in some scenarios that
is messing me up... anyways... I hope this isn't too much of a C question
as it is a Palm Dev Forum question.....

My function calls to the database for a particular record. The problem is
I'm trying to unpack it to my struct (onOrder) but I'm getting a "Chunk
under-locked" error.

So, how do I lock the chunk while passing it through the function....?!?!
My function definition below...

 static Err GetOrderRecord(DmOpenRef *dmReftoSync, UInt16 recordNum,
OnOrder *onOrder)
{
     Err err = 0;
     MemHandle myRecord = DmGetRecord(dmReftoSync, recordNum);

     if(!myRecord)
          err = DmGetLastErr();
     else
     {
          UnpackOnOrder(onOrder, (PackedOnOrder *)
MemHandleLock(myRecord));
          MemHandleUnlock(myRecord);
     }
     MemHandleUnlock(myRecord);
     return err;
}


Nole Mailey Data Conversion Specialist ProfitMaster Canada 1.800.340.4492 www.pmcanada.com [EMAIL PROTECTED]



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

Ted Beisler SPRUCE Computer Systems, Inc. [EMAIL PROTECTED]



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

Reply via email to