At 04:10 PM 8/25/2001 +0200, you wrote:
>Can I safely do this on a non-editable field ? The documentation let me
>thing it's not forbidden, but... is it safe ?


Yes, it's safe.  I learned it in the developers class in order to 
initialize "labels" that I wanted to be right justified and bold.

Here's my code:

/***********************************************************************
  *
  * FUNCTION:    SetTextFieldFromStringResource
  *
  * DESCRIPTION: This routine sets a read only
  *      text field from a string resource.
  *
  * PARAMETERS:  FormPtr pFrm
  *                              UInt16 FieldID
  *                              DmResID StringResource
  *
  * RETURNED:    nothing
  *
  * REVISION HISTORY:
  *
  *      8/19/2001       edg             Added to convenience.h
  *
  *
  ***********************************************************************/
extern void SetTextFieldFromStringResource(
         FormPtr pFrm,UInt16 FieldID,DmResID StringResource) {



         MemHandle hStringRes;
         UInt16 uwObjIdx;
         FieldPtr pFld;
         FontID oldFont;

         if(StringResource != NULL)
                 hStringRes = DmGetResource('tSTR',StringResource);
         else
                 hStringRes = NULL;
         uwObjIdx=FrmGetObjectIndex(pFrm,FieldID);
         pFld = (FieldPtr) FrmGetObjectPtr(pFrm,uwObjIdx);
         oldFont = FntSetFont(boldFont);
         FldSetTextHandle(pFld,hStringRes);
         FntSetFont(oldFont);
         if(StringResource != NULL)
                 DmReleaseResource(hStringRes);


}

I call this in both FormInit (with the ID of a resource):

         SetTextFieldFromStringResource(frmP,
                 LabelField,             // field ID of label field
                 LabelString);   // resource ID of string resource


and again with a NULL resource at FormDeinit.

         SetTextFieldFromStringResource(frmP,
                 LabelField,
                 NULL);

Bear in mind that I'm a newbie to this, but the code is working. Perhaps a 
more experienced person will tell us if I'm doing anything wrong.

</edg>


>-- Denis.
>
>
>// on frmOpenEvent :
>
>pText = getTextPtr();  // which returns a MemPtrNew'ed pointer
>if (pText)
>     FldSetTextPtr(fld, pText);
>else
>{
>     hText = DmGetResource(...);
>     FldSetTextHandle(fld, hText);
>}
>
>...
>
>// on frmCloseEvent :
>
>hText = FldGetTextHandle(fld);
>if (hText)
>{
>     DmReleaseResource(...);
>     FldSetTextHandle(fld, 0);
>}
>else
>{
>     pText = FldGetTextPtr(fld);
>     MemPtrFree(pText);
>}
>
>
>
>--
>For information on using the Palm Developer Forums, or to unsubscribe, 
>please see http://www.palmos.com/dev/tech/support/forums/



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

Reply via email to