The code looks OK so it sounds like a sequencing problem. Hard to tell
without more info.
Are you calling UpdateTextField() from the popup form's event handler?
Also "any field ... does not get erased when the original form gets
redisplayed" seems to imply that these fields remain on the screen while
everything around them is restored. Is this really what happens?
Regards, Nick
-----Original Message-----
From: J. Klapste [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, 12 October 1999 11:51
To: [EMAIL PROTECTED]
Subject: FrmReturnToForm() display update prob
Hi all,
This is probably a problem that has been hashed over mutiple times, so I
apologize ahead of time if you've seen it before.
I'm calling FrmPopupForm() to display some information in a couple of
fields, and calling FrmReturnToForm(0) when the user clicks the OK button.
After the popped-up form goes away, any field that _I_ updated via code
(see below) does not get erased when the original form gets redisplayed.
It's obviously programmer error, I just don't know the _right_ way to fix
the problem.
Here is the code that I'm using to update the text in the field. Note that
in most cases (at least that I remember) the field is set to editable. In
most cases, I just call the function once to set the fields value, and
don't touch the field anywhere else.
void UpdateTextField(UInt fieldID, CharPtr text, Boolean clearFirst) {
FormPtr form = FrmGetActiveForm();
FieldPtr field = GetObjectFormPtr(form, fieldID);
VoidHand textHand;
VoidHand newTextHand;
CharPtr textPtr;
CharPtr newTextPtr;
if ( field == NULL )
return;
if ( text == NULL )
return;
textHand = FldGetTextHandle(field);
if ( !clearFirst && textHand != NULL ) {
/* save the existing data */
textPtr = MemHandleLock(textHand);
newTextHand = MemHandleNew(StrLen(text) + StrLen(textPtr) + 1);
newTextPtr = MemHandleLock(newTextHand);
StrCopy(newTextPtr, textPtr);
MemHandleUnlock(textHand);
StrCat(newTextPtr, text);
MemHandleUnlock(newTextHand);
} else {
/* we don't care about the existing data */
newTextHand = MemHandleNew(StrLen(text) + 1);
newTextPtr = MemHandleLock(newTextHand);
StrCopy(newTextPtr, text);
MemHandleUnlock(newTextHand);
}
FldSetTextHandle(field, newTextHand);
FldDrawField(field);
if ( textHand != NULL )
MemHandleFree(textHand);
}
I've checked the obvious like making sure the handle passed into
FldSetTextHandle() is not locked by me (as you can see above). I've also
not passed NULL in later, so according to what I understand, the field
should free the handle when the field itself is freed. My reading of the
FldSetTextHandle() reference entry leads me to believe this.
The form being popped up is set to modal, and save behind.
I believe the field itself should be freed when FrmReturnToForm(0) is
called because thats what the reference entry says.
I'm not doing any custom drawing in the original form, nor any I doing
anything directly after the FrmPopupForm() call except returning true. I'm
not doing anything after the FrmReturnToForm(0) call except returning
true.
It looks like the field (maybe even the form) are not being cleaned up
correctly, but I'm too new to this to tell. Any pointers anyone?
Thanks
-Jason