How to draw/get a text string in a Field

Posted on 2004-11-27
Last Modified: 2013-12-27
I am programing a simple database application for Palm using Palm Development Suite downloaded from
I got a problem when putting a text in a Field Control.
Some Field Function can do this but they all need FieldType Pointer such as:

void FldSetText (
   FieldType *fldP,
   MemHandle textHandle,
   UInt16 offset,
   UInt16 size

Char *FldGetTextPtr (
   const FieldType *fldP

And i don't know how to get this Pointer. All i have here is FieldID only. I also need to get a Pointer(FormType*) of a Form when having it's ID.
I want that when i click on a button, my Field has to show a given text string.
Help me, thanks.
Question by:adchar43
    LVL 6

    Accepted Solution


    There is a FieldPtr type that is used to retrieve field's info from the Palm OS.

    You can find further info for it in the docs.

    Take a look at this Palm code (UPCASE comments are mine)

    Hope it can give you a starting point.

    static void NoteViewLoadRecord (void)
          UInt16 offset;
          FieldPtr fld;                             // THIS IS THE FIELD POINTER
          MemHandle recordH;
          Char * ptr;
          ApptDBRecordType      apptRec;

          // Get a pointer to the note field.
          fld = GetObjectPtr (NoteField);       // HERE YOU GET THE INFO

          // Set the font used in the note field.
          FldSetFont (fld, NoteFont);

          ApptGetRecord (ApptDB, CurrentRecord, &apptRec, &recordH);
          ErrFatalDisplayIf (! apptRec.note, "Invalid record");

          // Compute the offset within the appointment record of the note string.
          // The field object will edit the note in place, its is not copied
          // to the dynamic heap.
          ptr = MemHandleLock(recordH);
          offset = apptRec.note - ptr;
          FldSetText (fld, recordH, offset, StrLen(apptRec.note)+1);   //YOU HAVE TO PASS THIS POINTER TO THE FUNCTION

          MemHandleUnlock (recordH);
          MemHandleUnlock (recordH);            // was also locked by ApptGetRecord

    BTW, i find using FldSetTextHandle more secure (In other posts I mention that memory handle is a little bit difficult in PalmOS).

          DateTimeType dateP;
          FormPtr frm;
          FieldPtr fld;
          UInt32 ref;
          float valor;

                frm      = FrmGetActiveForm();
                getObjectPtr (fIndex);

                // get the field's old text handle
                MemHandle      oldH      = FldGetTextHandle(fld);
                //Copy our string into a memhandle
                int      len      = StrToShow.Length();
                MemHandle      mH      = MemHandleNew(len+1);
                char      *mP      = (char *) MemHandleLock(mH);

                //The memhandle needs to be unlocked to work...

                //To establish the field's link to the handle

                //To draw the field
                // get rid of old handle
                if (oldH != NULL)
                      MemHandleFree (oldH);

    Again, hope this can help you.

    Ivan Rivera

    Author Comment

    Thanks for you help but i am having a little bug, i can not get the pointer of my Field although i have my field's ID.
    I use this function:

    static void *GetObjectPtr(UInt16 rsrcID)  //<== COPY FROM DOCS
          FormPtr formP;
          formP = FrmGetActiveForm();
          return FrmGetObjectPtr(formP, FrmGetObjectIndex(formP, rsrcID));

    Fieldp = (FieldType *)GetObjectPtr(fieldFirstName);  <== Error cause by this function, i don't know why, i read in docs and they use this function like me.

    In your post above, is the function getObjectPtr the same with my function?

    I have the ID of the field resource, i want to set a text on this field, the text from Char * string(to test) not from my database.

    On your code above:
    FieldPtr fld;                             // THIS IS THE FIELD POINTER
    fld = GetObjectPtr (NoteField);       // HERE YOU GET THE INFO
    Is the function GetObjectPtr the same with my function and is NoteField = Your field ID?

    LVL 6

    Expert Comment

    by:Ivan Rivera, MTI, SCPM, ITIL, Cobit, PMP
    Could you please post all the code and the error message to try to figure out whats happening?


    Ivan Rivera

    Author Comment

    I founded my error, that i can not get the pointer of the Main Form and that cause this error.
    My new PROBLEM here :D



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    For a couple of years now I have used TrustGo  ( Security as the Security solution for my android phone.  I have tried many different options to provide the same protection, but this one seems to be the best. http…
    Preface: This article is part of a series focused on cross platform mobile app development (specifically Android and iOS) using the Alloy framework and Titanium Studio made by Appcelerator ( This article presumes a wor…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now