I don't know if these suggestions have been made yet... The new title should not be larger (including the NULL) than the original title. Or at least this use to be true on OS <= 4.x. The pointer that points to the name value must exist for the life of the form title. I have never assigned a new title using feature memory so I don't know how well it would work. Is it possible to retrieve the pointer to the current title and make your changes to that without allocating a new memory space? (assuming there isn't an unrelated memory issue causing the problem)
----- Original Message ----- From: "Patrick Lucas" <[EMAIL PROTECTED]> Newsgroups: palm-dev-forum To: "Palm Developer Forum" <[EMAIL PROTECTED]> Sent: Tuesday, August 17, 2004 2:41 AM Subject: Re: Crash when setting a form's title > Hi Ben > > I have tried to use FtrPtrNew() in the code fragment below but the same > crash occurs so I am wondering if I am missing something. > > char* pNew; > FtrPtrNew(DB_CREATOR, 0, StrLen(TITLE) + 1, (void**)(&pNew)); > DmSet(pNew, 0, StrLen(TITLE) + 1, 0); > DmWrite(pNew, 0, TITLE, StrLen(TITLE)); > FrmSetTitle(pForm, pNew); > > There are many improvements I could do to my code; I just want to get it > working first. By the way, is there a way of knowing what type a table cell > is? > > Kind regards > > Patrick > "Ben Combee" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > At 08:26 AM 8/16/2004, you wrote: > > >Guys > > > > > >I can't figure that one out. The following code works fine when pForm > points > > >to my program's own form but crashes when pForm points to a different > form. > > > > > >FormType* pForm = FrmGetActiveForm(); > > >char* pOld = (char*)FrmGetTitle(pForm); > > >char* pNew = (char*)MemPtrNew(6); > > >MemSet(pNew 6, 0); > > >MemMove(pNew, "Title", 5); > > >FrmSetTitle(pForm, pNew); > > > > Just using StrCopy(pNew, "Title) is adequate and faster than the MemSet > and > > MemMove. > > > > >The crash occurs on the last line. > > > > > >Could well be that the pointer returned by MemPtrNew() is valid for my > > >program's own form but not for any other form. How can I get a pointer > that > > >will be valid throughout the system (i.e. nol matter what program it gets > > >passed to)? > > > > This is correct. Each application gets its own memory owner ID, and when > > your application exits, the system will free any memory chunks allocated > to > > that ID. > > > > In Palm OS 5 and earlier, you can use MemPtrSetOwner to set the pointer's > > owner ID to 0, which is the system ID. However, if you do that, you'll > > have a memory leak since that text will never be freed -- closing the form > > won't deallocate your string. > > > > In this case, it's better to use Feature Memory with a FtrPtrNew. The > > pointer will stay valid, the memory won't be freed, but it will be tracked > > by your program and you can reuse the memory chunk or free it later. > > > > Still, overwriting the current form's title is pretty rude, and won't > > always work -- some forms don't have titles, for example. > > > > -- Ben Combee, DTS technical lead, PalmSource, Inc. > > "Combee on Palm OS" weblog: http://palmos.combee.net/ > > Palm OS Dev Fourm Archives: http://news.palmos.com/read/all_forums/ > > > > > > > > > > -- > For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
