If you define the title of a form in a resource, the form, whilst handling its initialization, accesses the resource and copies the contents of the title into local storage. It is this copy of the title that the title pointer initially points to. In current PalmOS implementations, the form allocates a large chunk of memory into which it stores information (including this title pointer AND its memory) about the form and its objects. You cannot (and the form does not) unallocate just the title on form close.
When you call FrmSetTitle, the form overwrites the title pointer but leaves the original title alone (though it is now unreferenced and unusable). The form does NOT separately unallocate the title pointer's memory at form close! Thus if you call FrmSetTitle, it is YOUR responsibility to manage the memory that your pointer references. This memory can have been obtained by MemPtrNew (or MemHandleNew), in which case you should call MemPtrFree (or MemHandleFree) on form close. It could also live in a database or resource -- you can call DmGetResource to get a resource's handle, lock it, then pass the pointer to locked resource memory in the FrmSetTitle call. In this case, you would need to call MemHandleUnlock and DmReleaseResource on form close. -bob mckenzie, palm pdx -----Original Message----- From: Andy Yeong [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 27, 2001 4:44 PM To: Palm Developer Forum Subject: Re: FrmSetTitle Usage Hi Robert, Robert McKenzie <[EMAIL PROTECTED]> wrote in message news:69206@palm-dev-forum... > > Using FrmSetTitle will work, but your intuition that you should do more is > quite correct. You have created a memory leak here. You should save your > title pointer (easiest as a global) and dispose of the memory referenced on > the form close event. Will FrmCloseEvent() to unload all the resources allocated to the form ? >You should also null this pointer on form open. If > you need to change the title multiple times, then you can dispose of a prior > version (if the title pointer global is non-null), create a new one, and > give it to the form. The reason to save the title pointer as a global and > not just to retrieve it from the form is that you must distinguish between > the title given in the resource (whose memory you don't want to free) and > ones that you set. (Of course there are other ways to do this, but this > seems most direct to me.) That explain why it doesn't work for me when I tried to retrieve the previous handle allocated to the title. -------------------------------------------------------------------------- titlePtr = FrmGetTitle( FrmGetActiveForm() ); titleH = MemPtrRecoverHandle(titlePtr); MemHandleResize(titleH, StrLen(new_title_from_database)+1); titlePtr = MemHandleLock(titleH); StrCopy(titlePtr, new_title_from_database); FrmSetTitle(frm, titlePtr); -------------------------------------------------------------------------- So sorry for this coming novice question, how do you declare global variables as I'm writing a few"C" files. I'm not too sure when will the variable cease to exsist. Is it possible to declare a variable that exist throught the lifespan of the program using CodeWarrior 7 ? > As to your overlapping problem, find the index of the form title object, > call FrmHideObject on it prior to changing the title, then FrmShowObject on > it after changing the title. To determine the title object's index, use a > simple loop (index=0; index<FrmGetNumberOfObjects(); index++). call > FrmGetObjectType(), and compare the returned value against a frmTitleObj. > When you get a bingo, you will have the title's index. Hmmm....sounds like a brilliant idea ! I do get the idea behind the above description, but I don't quite know how to fill up "FrmGetObjectType" as it require me to fill up the objectIndex as mentioned in the Palm OS API. Thank you for all the tips that you have shared with me ! It's really eye opening for a novice like me. Have a nice day ! Best Regards Andy -- 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/
