Hello all,
I get this error message when I call FldDrawField() after setting a new text in a
field.
"During a regular checkup, Palm OS Emulator determined that the dynamic heap chunk
with header
address 0x00005058 got corrupted. The "hOffset" field of the chunk header did not
reference a
memory location within a master pointer block."
The "Continue" and the "Debug" buttons are gray out, so the only thing I can do is
"Reset".
This is the snip code to set new text field, do you see anything wrong in the code?
Any idea or suggestion is very appreciated.
tnn
/***************************************************************************/
/* */
/* FUNCTION: SetFieldText, taken from utils.c in SimpleScan example */
/* */
/* DESCRIPTION:Perform all necessary actions to set a Field control's */
/* text and redraw, if necesary. Allocates a text handle. */
/* */
/* */
/* PARAMETERS: nFieldID(in) - The resource ID of the field. */
/* pSrcText(in) - The text to copy into field. */
/* nMaxSize(in) - Max size that the field can grow */
/* including nullChr */
/* bRedraw(in) - Should the text be redrawn now? */
/* */
/* RETURNED: None */
/* */
/***************************************************************************/
void SetFieldText(UInt16 nFieldID, const Char* pSrcText, Int16 nMaxSize, Boolean
bRedraw)
{
MemHandle hFieldText;
Char* pFieldText;
FieldPtr pField;
Int16 len;
UInt32 curSize;
pField = (FieldPtr)GetObjectPtr(nFieldID);
if(!pField)
return;
hFieldText = FldGetTextHandle(pField);
if(!hFieldText) {
hFieldText = MemHandleNew(nMaxSize);
// If already allocated, make sure it can handle nMaxSize already.
// If not, realloc that buffer
} else {
curSize = MemHandleSize(hFieldText);
if(curSize < nMaxSize)
MemHandleResize(hFieldText, nMaxSize);
}
if( hFieldText ) {
len = StrLen(pSrcText);
pFieldText = (Char*)MemHandleLock(hFieldText);
if (len > nMaxSize - 1) {
StrNCopy( pFieldText, pSrcText, nMaxSize-1);
pFieldText[nMaxSize-1] = nullChr;
} else {
StrCopy(pFieldText, pSrcText);
}
MemHandleUnlock(hFieldText);
FldSetTextHandle(pField,(MemHandle)hFieldText);
FldSetTextAllocatedSize(pField,nMaxSize);
FldSetMaxChars( pField, nMaxSize-1);
FldRecalculateField( pField, true );
if(bRedraw)
FldDrawField( pField );
}
}
In the contrustor, the text field is set
usable
editable
underline
single line
not dynamic size
left justified
max characters: 64
This is the function call
Char authorstr[41] = "Thunguyet nguyen";
SetFieldText(RecordAuthorField, authorstr, 41);
Do I have to set dynamic size for the field because I have to set different text (with
different
length) for the field? Is that my problem?
__________________________________________________
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes
http://autos.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/