From: "JAMES S HAINES" <[EMAIL PROTECTED]>
> The emulator is returning an error indicating an unlocked chunk error. As
it
> explains this is caused by trying to use a pointer returned by a handle
> after it has been unlocked. I suspect there may be something wrong in this
(snip)
> char *getFieldText(UInt16 fieldID)
> {
> FieldType *fldP;
> Char *fieldText;
> MemHandle h;
> fldP=getObjectPtr (fieldID);
> h=FldGetTextHandle(fldP);
> if (h !=NULL)
> {
> fieldText= MemHandleLock(h);
> FldSetTextHandle(fldP,h);
> MemHandleUnlock(h);
> }
> else
> fieldText=NULL;
> FldSetTextHandle(fldP,NULL);
> return fieldText;
> }
You're obtaining a pointer to a locked chunk, returning that pointer, then
unlocking the chunk. In theory this pointer is now invalid, although OS
memory functions can probably still recognise it as belonging to a chunk
and warn you accordingly. Now the interesting part of this is that Palm OS
will lock the chunk when the field is given it again (or the next time it
wants
to write to the field, no idea which) so the FldSetTextHandle(fldP,h) is a
bit
confusing, particularly since you disconnect the field from the handle soon
after using FldSetTextHandle(fldP,NULL);
I prefer only to return a char * when returning a simple pointer. If you're
returning a chunk it's better to return an unlocked handle so that it's
obvious to the calling code that the chunk has to be locked before use.
Chris Tutty
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/