I haven't been in this discussion from the beginning, but looking at its
header and the first sentence, I believe what you need is
FrmCopyLabel(FormType* frm, UInt16 lid, const Char* newtext);
I sort of agree that the name is not very easy to find and the docs lack
handy reference to it where you would expect to see it. Yet, the function
itself is there and works like a charm.
Enjoy,
bobby
(who re-did all his controls back to labels after finding that function a
few days ago)
-----Original Message-----
From: Steve Achelis [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, April 10, 2001 4:27 PM
To: Palm Developer Forum
Subject: Re: OS4.0: Control.c Line 543, Not a control object
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/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/