This is what you are supposed to do, as long as you realise that the 
pointers in your struct point to memory in the database record. If you do a 
MemHandleUnlock in the //etc etc, then your struct will no longer point to 
valid memory.

You can use StrLen on the pointers to find the length of the strings 
(assuming you have packed them properly with NULL terminators which should 
be evident during unpacking).

Also, care must be taken when modifying the strings and repacking them, 
since you may have to allocate new (dynamic) memory temporarily for the 
modified fields.

Matt

At 08:35 AM 2/4/2002 -0800, you wrote:
>Kade:
>
>   Perhaps the following snippet will give you some ideas:
>
>// note that this function leaves the record locked
>// if and only if it returns 0 (no err)
>
>Err YourUnpack(
>   DmOpenRef pDb,        // IN database reference
>   UInt16 index, // IN record index
>   MLSDB * pRec) // IN/OUT pointer to struct, to be filled in
>{
>         Char* p;
>         MemHandle h;
>         Int32 len;
>
>         h = DmQueryRecord(pDb, index);
>         if (h)
>         {
>                 MemSet(pRec, sizeof(MLSDB), 0);
>                 p = MemHandleLock(h);
>
>                 // date
>                 len = StrLen(p);
>                 pRec->date = p;
>
>                 // away
>                 p += len;
>                 len = StrLen(p);
>                 pRec->away = p;
>
>                 // etc., etc.
>         }
>         else
>         {
>                 return -1;
>         }
>         return 0;
>}
>
>
>-----Original Message-----
>From: Kade P. Cole [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, April 02, 2002 8:14 AM
>To: Palm Developer Forum
>Subject: Re: Palm PDB Database Help
>
>
>
>I must not have explained it well. The Databse record in the PDB DOES
>contain the character strings. The struct that I am using to access the DB
>record is the one with the pointers in it.
>
>Kade
>
>
>On 4/2/02 9:51 AM, "Robert McKenzie" <[EMAIL PROTECTED]> wrote:
>
> > Kade:
> >
> > You have a basic C misconception here.
> >
> > A DB record should (can only) contain that actual strings themselves, NOT
> > pointers to them.
>
>--
>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