How to draw/get a text string in a Field

I am programing a simple database application for Palm using Palm Development Suite downloaded from http://www.palmsource.com.
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.
adchar43Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivan Rivera, MTI, SCPM, ITIL, Cobit, PMPProject ManagerCommented:
Hi...

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);

            StrCopy(mP, StrToShow.data());
            
            //The memhandle needs to be unlocked to work...
            MemHandleUnlock(mH);

            //To establish the field's link to the handle
            FldSetTextHandle(fld,mH);

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

Again, hope this can help you.

Ivan Rivera
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
adchar43Author Commented:
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.


Thanks
---------------------
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?

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

Thnks

Ivan Rivera
0
adchar43Author Commented:
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

I CAN NOT GET THE POINTER OF THE MAINFORM, AND I DON'T KNOW WHY

http://www.experts-exchange.com/Programming/Wireless_Programming/Palm_Pilot/Q_21222707.html

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Smartphone Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.