Hello all,

I have a strange problem and am looking for some kind of explanation.  I
have an app that uses several tables on several forms.  On all of these
tables I have from 1 to 2 columns that are custom drawn text fields which I
use to display values that I store.  I use the method shown in Palm
Programming (O'Reilly), and it works very well.  However, I recently tried
it on a Palm V emulator and ran into a problem which did not appear on the
Emulator running a Palm 4.1 device.

I use the following as the custom drawing function:

static void DrawData(VoidPtr table, Word row, Word column, RectanglePtr r)
{
   FieldPtr fld;

   fld = InitDataField(table, row, column, r, true);
        // in the debugger fld = 0xfffc868

   FldDrawField(fld); // This is where I get a bus error because fld does
not
                            // equal the value that was to be returned from 
InitDataField.
   FldFreeMemory(fld);
}

static FieldPtr InitDataField(VoidPtr table, Word row, Word column,
RectanglePtr r, Boolean temp)
{
   VoidHand textH;
   CharPtr textP;
   char buf[10];
   FieldPtr fld;
   ClockRow * i;
   UInt index = TblGetRowID(table,row);
   Int32 ElapsedTime;
   Int32 *lp1;
   Int32 *lp2;
   fld = &gTempFieldType;
   MemSet(fld, sizeof(FieldType), 0);
   RctCopyRectangle(r, &fld->rect);
   fld->attr.usable = true;
   fld->attr.visible = !temp;
   fld->attr.editable = false;
   fld->attr.singleLine = true;
   fld->attr.dynamicSize = false;
   fld->attr.underlined = true;
   fld->attr.insPtVisible = true;
   fld->attr.numeric = false;
   fld->attr.justification = leftAlign;
   fld->maxChars = 10;

   // load up textH with some text based on the Row ID stored in index
   FldSetTextHandle(fld, (Handle)textH);
   return fld; // in debugger = 0x01c868
}

This works in an application on the Palm V, but in another application which
is bigger (and uses the same global FieldType variable, gTempFieldType, many
more times) the FldDrawField(fld) line causes a crash.  In the debugger I
find that the fld value returned from the InitField routine is different
from the fld as created in the InitField.  Why would this be the case?  I
have a feeling it is related to memory usage on the heap, but don't know
what I can do to correct it.  For the time being I have collapsed all of the
logic into the first routine, so that the fld variable is all handled in
that routine and then it works just fine.

Any ideas?

Paul Gibson


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

Reply via email to