First of all, keep in mind that I'm rather new at Palm
programming. :)

When modifying a field's text, the book I use for
reference (the great book by O'reilly) states that
"you must use a handle instead of a pointer.  The
ability to resize the text requires the use of a
handle."  It then shows an example, which I used in my
code:

static FieldPtr SetFieldTextFromHandle(Word fieldID,
Handle txtH)
{
  Handle oldTxtH;
  FormPtr frm = FrmGetActiveForm();
  FieldPtr fldP;
  
  //Get the field's current text handle
  fldP =
FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,fieldID));
  oldTxtH = FldGetTextHandle(fldP);
  
  // set the field's text to the new text
  FldSetTextHandle(fldP,txtH);
  FldDrawField(fldP);
  
  //free the handle AFTER we call FldSetTextHandle().
  if (oldTxtH)
    MemHandleFree(oldTxtH);
    
  return fldP;
}

This, as well as several wrapper functions for it
(most provided by the O'reilly book as well), allows
me to pretty much do whatever I need to do with a
field's text.

I hope this helps (and that I'm not stupidly stating
the obvious!)

Alias,
Fletch





--- Mike Davis <[EMAIL PROTECTED]> wrote:
> > Are you willing to give a snippet of code, showing
> the
> > offending line, as well as a few lines above and
> > below?
> 
> I can give you all the lines of code for problem 2. 
> I still have
> not figured out exactly where the error is on
> problem 1.  I see one 
> on power up and after many operaionts.
> 
> But problem 2 is easy to show:  Basically I have a
> form with a field 
> where a number is displayed in the field.  When the
> number of digits 
> goes from 1 to 2 or 2 to 1 there is an "invalid
> field length" error.  
> If I go from 2 to 2 or 1 to 1, there is no error.  
> 
> The field is non editable and initial size set to
> 10.  All I do is
> determine the number and convert it to a string.  I
> then call
> a function and pass the pointer to the string.  The
> string is a 
> global array, so it has global life.
> 
> The function that does the conversion:
> 
>     StrIToA(curBtnStr, fmod(btn,12) + 1);
>     SetFieldText(fldBtn, curBtnStr);
> 
> Here is the function call that I use to set the
> field text:
> 
> void SetFieldText(Word id, char *s) {
>     FormPtr frmp;
>     FieldPtr fldp;
>     FieldAttrType fa;
> 
>     frmp=FrmGetActiveForm();
>     fldp=FrmGetObjectPtr(frmp,
> FrmGetObjectIndex(frmp, id));
>     FldGetAttributes(fldp, &fa);
> 
>     if (fa.editable == TRUE){
>         FldDelete(fldp, 0, FldGetTextLength(fldp));
>         FldInsert(fldp, s, StrLen(s));
>     }
>     else{
>         FldSetSelection(fldp, 0,0);     // clear
> selections
>         FldSetTextPtr(fldp, s);
>     }
>     FldDrawField(fldp);
> }
> 
> That is the entire code.  If I comment out the
> SetFieldText(), there 
> is no error (obviously).  But I don't see any
> problem with this 
> method of writing text to a field.  I do this many
> other places 
> without problems.
> 
> Any clues?
> 
> 
> 
> > Fletch
> > 
> > --- Mike Davis <[EMAIL PROTECTED]> wrote:
> > > I have tested my app as a PalmIIIx using Bebug
> Rom
> > > 3.0.  Every
> > > thing tests ok.
> > > 
> > > Then I switched to using 3.3 Debug ROM and get
> two
> > > errors
> > > immediately.  I'm sure there will be others. I
> need
> > > to fix this 
> > > quickly as possible as the app is already
> released. 
> > > Fortunately, it 
> > > recommends OS 3.0 but I would like it compatible
> > > with all versions of 
> > > the OS.
> > > 
> > > The two errors:
> > > 1) Field.c, Line: 123, Invalid insertion point
> > > position.
> > > 
> > > 2) Field.c, Line: 136, Invalid Field Length. 
> This
> > > one appears to
> > > happen when the output to the field changes
> size. 
> > > My output is either
> > > one digit or two digits.  If I change from one
> value
> > > to another and
> > > both are single digit, no problem.  If I change
> from
> > > one value to 
> > > another and both are 2 digits, no problem.  The
> > > problem occurs when 
> > > going from 2 to 1 or 1 to 2 only.  The field
> width
> > > attribute is
> > > set to 10.
> > > 
> > > I would like to understand these two errors.
> > > 
> > > First, would either of these two cause a Fatal
> Error
> > > on a palm using
> > > OS 3.3, or is just something that POSE catches
> that
> > > should be fixed.
> > > 
> > > Second, why is this an error in 3.3 but not in
> 3.0? 
> > > Cause?  
> > > --
> > >
> >
>
-----------------------------------------------------------------
> > > Discussion Group:       
> > > http://www.halcyon.com/ipscone/wwwboard/
> > > 
> > > Protect your constitutional rights. Your
> favorite
> > > one may be next!
> > >
> >
>
-----------------------------------------------------------------
> > > 
> > > 
> > 
> > 
> > =====
> > 
> >
>
----------------------------------------------------------------
> > 
> > Lottory (n): A tax on people who failed math.
> > 
> > __________________________________________________
> > Do You Yahoo!?
> > Talk to your friends online with Yahoo! Messenger.
> > http://messenger.yahoo.com
> > 
> 
> 
> --
>
-----------------------------------------------------------------
> Discussion Group:       
> http://www.halcyon.com/ipscone/wwwboard/
> 
> Protect your constitutional rights. Your favorite
> one may be next!
>
-----------------------------------------------------------------
> 
> 


=====

----------------------------------------------------------------

Lottory (n): A tax on people who failed math.

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://messenger.yahoo.com

Reply via email to