• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

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.
0
adchar43
Asked:
adchar43
  • 2
  • 2
1 Solution
 
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
 
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

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now