> From: [EMAIL PROTECTED]
>
> void MainFormDoMQe( void )
> {
>    MQEBYTE byteBuf[]={0x31,0x32,0x33,0x34 }; /*By Eugene*/
>    MQEBYTE *byteBufs;
>    SetFieldTextFromStr( MainErrorField, (char *)byteBuf); /*??????Here has
> error*/
>    SetFieldTextFromStr( MainErrorField, (char *)byteBufs); /*??????Here
> also has error*/
> }
>

Eugene -

There were several errors in your code -- too many to respond to them all.
However, your basic question is "how can I write an array of bytes to the
screen.  The answer is two fold:

1)  Don't mess with the definitions of the parameters in SetFieldTextFromStr
and SetFieldTextFromHandle.  Here is some working code:

/***********************************************************************
 * 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


2) The second part has to do with converting your array of bytes to a
string.  Here is one way:

   UInt8 byteBuf[] = {0x31,0x32,0x33,0x34};
   Char byteChars[5];

   MemMove(byteChars, byteBuf, 4);
   byteChars[4] = '\0';
   SetFieldTextFromStr(MainErrorField, byteChars);

Note that I changed MQEBYTE to UInt8.  You didn't show how you defined
MQEBYTE.  If it actually is a single byte, then use UInt8, which is the same
as an unsigned char.  Depending on how you defined MQEBYTE, you may have to
use a different method to convert it to chars.


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