You've got a bug there, and the compiler warned you ;)

CharPtr c points to *nothing* (or worse, a random address)

You need to allocate some memory for c to point to!

Something like this:

     UnpackTrip(&theTrip, p);

     // ALLOCATE SOME SPACE!!!!
     c = MemPtrNew(StrLen(theTrip.TripNumber)+1);
     // OK, now can copy & return

     StrCopy(c, theTrip.TripNumber);
     MemHandleUnlock(record);

You probably *do* want to use DmQueryRecord() as it seems you're not
modifying the record.

-- John Schettino
Palm OS Programming for Dummies: http://schettino.tripod.com/

-----Original Message-----
From: Timothy Astle [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 13, 2000 11:24 AM
To: Palm Developer Forum
Subject: Bewildered...


CharPtr GetTripTripNumber(UInt UniqueID)
{
     CharPtr c;
     tblTrip theTrip;

     VoidHand record = DmGetRecord(gTripDB, UniqueID);
     tblPackedTripPtr p = MemHandleLock(record);
     UnpackTrip(&theTrip, p);
     StrCopy(c, theTrip.TripNumber);
     MemHandleUnlock(record);

     return(c);
}


This function has been causing me much grief :-)  Here's what I've
encountered thus far:

#1 It warns me that I should initialize CharPtr c before using it. (why??)
#2 When I use DmGetRecord, I get an "Index out of Range" error, requiring a
hard boot
#3 If I change DmGetRecord to DmQueryRecord, and comment out all the other
code, I get a different error.  (NULL based error, probably due to the fact
I hard coded a NULL for a return value :-)

Now, I've heard something about clearing the busy bit... perhaps this has
something to do with my problem?  I am aware that DmQueryRecord doesn't set
the busy bit...

Tim



-- 
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to