The purpose of packing and unpacking these structures is to save space and
make it easier to save to the database.  If you are like most of us, by the
time you get ready to save a form, you have data bits all over the place.
Some are still in the form, some may be in global variables, etc.  The pack
function gives you a way to put it in one structure and than save to the
database.  Unpack is used to separate all of the data and put it back in the
form when you reenter.

In general, people use the following process for unpacking:
1. grab the record handle
2. lock the record handle
3. call the unpack routine with a record pointer and some local record to
unpack to
4. place information in the form
5. unlock and, maybe, release the record.

If the customer parameter below is in the same order as packedCustomer
record handle, you can point customer at it to get the record information.
If you have a series of CharPtr's on the other hand, you will have to
manually find the beginning of the strings with customer, since
PackedCustomer is locked and pointers cannot be moved.

Hope this helps answer your question.
Elia

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 28, 1999 2:23 AM
To: [EMAIL PROTECTED]
Subject: Pack and Unpack question




Dear all,

According to the example of UnpackCustomer shown on the book of Palm
Programming,

the function prototype of UnpackCustomer is :
static void UnpackCustomer(Customer *customer, const PackedCustomer
*packedCustomer)

However the voidPtr to the locked record is passed as the second parameter.
Even so, packedCustomer->customerID and packedCustomer->name is still
valid. Is it because of the fact that every element in a structure is
written consecutively and in the order specified in the structure
declaration?

Thanks very much!

philip

P.S. Is the same technique of pack and unpack usually used in networking
programe?




Reply via email to