This is the code I just tried per your suggestion.  I got a chunk
under-locked error on the line with the arrow pointing to it.  I think I
tried every possible variation of this code.  It was in one of the tomes I
looked at.  Note that I only have a problem when the user enters text into
this field.  I don't think my problem could have been caused by the size in
MemHandleNew because I am only entering two characters.

void UpdateField(ULong newtime, ULong fieldname){
  FieldPtr fld;
  FormPtr frmP;
        VoidHand oldhand;
        VoidHand newhand;
        CharPtr fldptr;
        Int fldIndex;

        frmP = FrmGetActiveForm();
        fldIndex = FrmGetObjectIndex(frmP, fieldname);
        fld = FrmGetObjectPtr(frmP, fldIndex);
        oldhand = FldGetTextHandle(fld);
        newhand = MemHandleNew(11);
        fldptr = MemHandleLock(newhand);
        StrIToA(fldptr, newtime);
        MemPtrUnlock(fldptr);
-->     FldSetTextHandle(fld, newhand);
        FldDrawField(fld);
        if (oldhand) MemHandleFree(oldhand);

}

        I have another routine that executes first that reads what the user typed
into any one of the six fields he can edit.  At present the program goes
through this without incident but it's reading the same fields.  I've tried
both routines several dozen different ways.  I can't help but think there's
something that should be obvious that I don't know.  I have the Palm OS
Bible and some of the on-line stuff I printed out or read on-line.  Is there
another good reference you'd recommend?

ULong ReadField(ULong fieldname){
  FieldPtr fld;
  FormPtr frmP;
//      VoidHand oldhand;
        CharPtr fldptr;
        Int fldIndex;
        ULong fldvalue;

        frmP = FrmGetActiveForm();
        fldIndex = FrmGetObjectIndex(frmP, fieldname);
        fld = FrmGetObjectPtr(frmP, fldIndex);
        fldptr = FldGetTextPtr(fld);
        if (!(fldptr)){
                return (0);
        }
        fldvalue = StrAToI(fldptr);
        MemPtrUnlock(fldptr);
        return fldvalue;


}

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Michael
Glickman
Sent: Sunday, November 25, 2001 10:54 PM
To: Palm Developer Forum
Subject: RE: Editing Fields


As far I remember, this is almost exact
replication from PalmOS reference guide.

It really looks safe, but it means that you
relocate memory all the time, that might
result in heap fragmentation. Wouldn't it
be better to free old handle before getting
the new one, given that you don't use
its content ?

Michael


-----Original Message-----
From: Brian Smith [mailto:[EMAIL PROTECTED]]
Sent: Monday, 26 November 2001 2:44 PM
To: Palm Developer Forum
Subject: RE: Editing Fields


On Mon, 26 Nov 2001, Michael Glickman wrote:

> You need MemHandleNew(11)  having an extra byte for trailing zero.

Maybe, maybe not.  Better safe than sorry, though.  After looking at the
code myself it looks like half of it is pretty unnecessary... and unsafe.
You don't have the certainty that any existing buffer for the field is
going to hold the new text going in.  The same thing is better acomplished
with the following code (newhand is just another VoidHand).

        frmP = FrmGetActiveForm();
        fldIndex = FrmGetObjectIndex(frmP, fieldname);
        fld = FrmGetObjectPtr(frmP, fldIndex);
        oldhand = FldGetTextHandle(fld);

        newhand = MemHandleNew(11);
        fldptr = MemHandleLock(newhand);
        StrIToA(fldptr, newtime);
        MemPtrUnlock(fldptr);
        FldSetTextHandle(fld, newhand);
        FldDrawField(fld);

        if (oldhand)
                MemHandleFree(oldhand);

----------------------------------------------------------------------
Brian Smith  //   [EMAIL PROTECTED]   //  http://www.arthurian.nu/
Software Developer  //  Gamer  //  Webmaster  //  System Administrator
Echelon Teasers: NSA CIA FBI Mossad MI5 Cocaine Cuba Revolution Espionage


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

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



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

Reply via email to