I see.... Your subroutine will not work for a modal form.
First of all you call FrmGetActiveForm, but your modal form is not
active before you call FrmDoDialog, so it gives you the wrong form.
And, you draw to the screen.
One solution would be to add 2 params to your routine:
the FormPtr , and a Boolean that says if you allow to draw.
void SetFieldStrValue ( FormPtr frm, UInt16 fieldID, Char *value,
Boolean bAllowDraw )
{
...
if( bAllowDraw )
{
FldDrawField( fld );
}
}
Note: When the modal form gets initialized, the field handle is null
so I dont think you have to free an existing handle.
But this is not perfect because it requires you to think about whether
you allow drawing everytime you call the routine.
I have my routines too but organized like this (error checking removed
for clarity):
MemHandle AllocHandleFromText( char *text )
{
len = StrLen( text );
h = MemHandleNew( len + 1 );
return h,
}
Then, for a modal form:
frm = FormInitForm( ID );
fld = FldGetObjectPtr( frm, ... );
h = AllocHandleFromText( text );
FldSetTextHandle( fld, h );
FrmDoDialog( frm );
FrmDeleteForm( frm );
The init is only three calls, it's not too bad, and flexible enough.
The AllocHandleFromText gets used in lots of situations.
I use this on all my projects.
I tried the one-routine-that-does-everything approach before, and
there's always a case where it doesn't work....... ! (as you just
noticed :) )
HTH
O.Lancelot
On Thu, 23 Jun 2005 09:57:48 -0000, "Dr. Vesselin Bontchev"
<[EMAIL PROTECTED]> wrote:
>> // init the fields though they are not visible yet
>> fld = FrmGetObjectPtr( frm, ... );
>> FldSetTextHandle( fld, h );
>
>Ah... Problem is, I have a whole subroutine for doing this stuff (writing a
>string to a field), because normally a bunch of other things have to be done
>too, and this subroutine calls FldDrawField at the end, which writes to the
>screen:
>
>void SetFieldStrValue (UInt16 fieldID, Char *value)
>{
> FormPtr frmP;
> FieldType *fldP;
> Char *fieldText;
> MemHandle h;
>
> frmP = FrmGetActiveForm ();
> fldP = FrmGetObjectPtr (frmP, FrmGetObjectIndex (frmP, fieldID));
> h = FldGetTextHandle (fldP);
> FldSetTextHandle (fldP, NULL);
> if (h == NULL)
> h = MemHandleNew (StrLen (value) + sizeOf7BitChar (chrNull));
> else
> MemHandleResize (h, StrLen (value) + sizeOf7BitChar (chrNull));
> fieldText = MemHandleLock (h);
> StrCopy (fieldText, value);
> MemHandleUnlock (h);
> FldSetTextHandle (fldP, h);
> FldDrawField (fldP);
>}
>
>Regards,
>Vesselin
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/