"lklee" <[EMAIL PROTECTED]> writes:

> I am using the follow function to set an text to an Field But that always
> return, is there anyone who can help me to solve it.
> 
> static void SetField( FormPtr frmP, unsigned short field_id, char *text )
> {
>     // Set the associated field's text
>     FieldPtr fld = (FieldPtr)GetObjectPtr( frmP, field_id ) ;
>     Handle h = FldGetTextHandle( fld );

There is no guarantee that the field will have a valid text handle. You
should check for h==NULL and allocate a handle if so. 

>     StrCopy( (CharPtr)MemHandleLock( h ), text );

Even if h has a handle, there's no guarantee that it is big enough to
hold text. You should still allocate a new handle and destroy the old
one.

Here is a better approach:

 static void SetField( FormPtr frmP, unsigned short field_id, char *text )
 {
     // Set the associated field's text
     FieldPtr fld = (FieldPtr)GetObjectPtr( frmP, field_id ) ;
     Handle h = FldGetTextHandle( fld );
     FldSetTextHandle( fld, NULL );
     if (h) MemHandleFree(h);
     h = MemHandleNew( StrLen(text) + 1 );
     StrCopy( MemHandleLock( h ), text );
     FldSetTextHandle( fld, h );
     FldDrawField( fld );
 }


-- 
Dave Carrigan ([EMAIL PROTECTED])            | YOW!!  Up ahead!  It's a DONUT
UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS | HUT!!
Seattle, WA, USA                            | 
http://www.rudedog.org/                     | 


-- 
For information on using the ACCESS Developer Forums, or to unsubscribe, please 
see http://www.access-company.com/developers/forums/

Reply via email to