> From: [EMAIL PROTECTED]
>
> Hey! I am new to coding for the Palm Os platform. I have code
> warrior and I am writing a simple addition program to get use to
> coding for the palm os platform. I have figured out the button
> down event and things like that but am having trouble changing
> the text property of a label and a field through code.
>
Here are 2 functions you will find useful:
/***********************************************************************
* Sets text in a field to textP, given an object ID and a text MemHandle
***********************************************************************/
static FieldPtr SetFieldTextFromHandle( UInt16 fieldID, MemHandle txtH )
{
MemHandle oldTxtH;
FormPtr frm = FrmGetFormPtr( MainForm );
FieldPtr fldP;
// get the field and its text MemHandle
fldP = FrmGetObjectPtr( frm, FrmGetObjectIndex( frm, fieldID ) );
ErrNonFatalDisplayIf( !fldP, "missing field" );
oldTxtH = FldGetTextHandle( fldP );
// set field to new text
FldSetTextHandle( fldP, txtH );
FldDrawField( fldP );
// free old MemHandle
if ( oldTxtH ) MemHandleFree( oldTxtH );
return fldP;
} // SetFieldTextFromHandle
/***********************************************************************
* Sets text in a field to textP, given an object ID and a string
***********************************************************************/
static FieldPtr SetFieldTextFromStr( UInt16 fieldID, Char *strP )
{
MemHandle txtH;
txtH = MemHandleNew( StrLen( strP ) + 1 );
if ( !txtH )
return NULL;
StrCopy( MemHandleLock(txtH), strP );
MemHandleUnlock( txtH );
return SetFieldTextFromHandle( fieldID, txtH );
} // SetFieldTextFromStr
The functions required to set a text field are all documented in the Palm OS
Programmer's API Reference, but since you're new, these two functions will
help. To change the text of a label, use CtlSetLabel. You can read about
it in the docs.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/