I ended up replacing my labels with non-editable, non-underlined fields.  I
then wrote the following SetField() function that sets my text into the
field.  This works well, as it avoids the 4.0 complaints and I don't have to
worry about overflowing the label.

extern void SetField( FormPtr pForm, UInt16 uiField, Char *szNewText )
{
    FieldType * pField;
    MemHandle hText;
    Char *szText;
    UInt16 uiNewSize;
    UInt16 uiMaxChars;

    // The following concept came from Reference.pdf in the discussion of
FldGetTextHandle.
    pField = FrmGetObjectPtr(pForm, FrmGetObjectIndex(pForm, uiField));

    uiNewSize = StrLen( szNewText ) + 1; // "+1" for null terminator
    uiMaxChars = FldGetMaxChars( pField );

    // Get the handle for the current string
    hText = FldGetTextHandle( pField );

    // If there is a handle attached to the field, free and detach it
    if( hText )
    {
        FldSetTextHandle( pField, NULL);
        MemHandleFree( hText );
    }

    // Allocate a new memory chunk that will contain the data.
    hText = MemHandleNew( uiNewSize );

    // Lock the handle and get a pointer to the memory chunk.
    szText = MemHandleLock(hText );

    StrNCopy(szText, szNewText, uiMaxChars);

    // Unlock the new memory chunk (must be unlocked before call to
FldSetTextHandle()).
    MemHandleUnlock( hText );

    // Set the field's text to the data in the new memory chunk.
    FldSetTextHandle(pField, hText );

    // Update the text in the field.

    // THIS WILL CRASH IF YOU HAVEN'T FIRST CALLED FrmDrawForm()
    // (or if you have called FrmEraseForm().

    FldDrawField(pField);
}

"Steve Achelis" <[EMAIL PROTECTED]> wrote in message
news:43361@palm-dev-forum...
>
> That certainly makes for some difficult to maintain code.  Now I have to
go
> to every form and make sure any label that I might change programmically
has
> a long enough static string.  I then have to create defines to limit the
> lengths of my strings in my code.  And I have to remember that if I ever
> change the length of the defines, I have to lengthen the string in the
> forms.  sick!
>
> Steve
>
> "David Fedor" <[EMAIL PROTECTED]> wrote in message
> news:43205@palm-dev-forum...
> >
> > > My app sets the text associated with a label using CtlSetLabel().  It
> > works
> > > fine on OS < 4.0.  However, on 4.0 I get the following error message
> from
> > > the emulator: "...Control.c Line 543, Not a control object."
> >
> > What sort of object are you passing in to CtlSetLabel?  If you're like
the
> > normal case that this message is designed to help, then you're probably
> > trying to change the text of a label object.  A label object isn't a
> > control.  Use FrmCopyLabel.
> >
> > CtlSetLabel used to work but that was only by luck; the routine didn't
use
> > to check its object type and the structs happened to be similar enough
in
> > this respect.  But that isn't guaranteed to be the case in the future.
> >
> > -David Fedor
> > Palm Developer Support
> >
> >
>
>
>
>



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