Todd: Dave's original comment still holds with this code. True you allocate memory with MemPtrNew and store a pointer to the newly allocated memory in startTime and endTime. But then you immediately set the startTime and endTime pointers to point to the current labels -- effectively rendering your new memory inaccessible. Simply delete the "startTime = CtlGetLabel(..." and "endTime = CtlGetLabel(..." lines.
But even then, you must add more code to keep track of any memory you allocate for these labels. If this is done once and only once (on form open), then you can, on form close, retrieve pointers from the controls for the labels and free that memory. If this can be done more or less than one time for each control (say dynamically in response to time changes or user input), then you need to track (1) whether you have already allocated your own memory for the labels, (2) free dynamically allocated label memory before setting the labels the second and each subsequent time, and (3) if you have allocated label memory, free it on form close. A handy way to do this is to make startTime and endTime be global (for this form) and initialize them to NULL prior to allocating any memory and after freeing any previously allocated memory. By the way, an alternate approach is to set the control's label up with sufficient memory to hold whatever label you wish to stuff into it (blanks are handy for this purpose). Then use CtlGetLabel to get a pointer to that memory and simply write your new label into it. In this case you don't use CtlSetLabel, as the label pointer doesn't change, just the contents of the memory (which is actually in the form structure) which it points to. This is simpler (in my opinion), but somewhat less flexible. Note you also have to force a draw -- FrmHideObject (prior to mucking with the label) and FrmShowObject (after mucking about) are handy ways to do this, and somewhat less intrusive (visually) than CtlDrawControl. **WARNING** You absolutely MUST know the maximum number of characters that can EVER be used for the label. It is easy to overwrite the label memory! If you do this, you will clobber the form pointer -- with devastating consequences which are REALLY difficult to debug (I know, having been there and done that). -bob mckenzie, palm pdx -----Original Message----- From: Todd C. Johnson [mailto:[EMAIL PROTECTED]] Sent: Friday, January 04, 2002 6:33 AM To: Palm Developer Forum Subject: Re: Trouble with selector triggers Thank you for you assistance. I have changed my code like you said (at least I thought I did). I am still having the same problem. When the StartTime code is befor the EndTime code, I get the "Object not in form" error. Below is the code with changes. This time I included the entire function. Thank you again, Todd static void ServicePeriodFormOpen(FormPtr) { MemHandle currentRecordH; ServDBRecord *currentRecordP; FormPtr frmP; static Char datelbl[20]; Char *startTime; Char *endTime; static Char *startlbl; static Char *endlbl; FieldType *datefldP; frmP = FrmGetActiveForm(); // Get ServicePeriod record currentRecordH = DmQueryRecord(gServDB, gCurrentIndex); currentRecordP = MemHandleLock(currentRecordH); // Save current record in global for later reference gCurrentRecord = *currentRecordP; // Move date to screen DateToDOWDMFormat(gCurrentRecord.start.month, gCurrentRecord.start.day,gCurrentRecord.start.year, sysPrefs.longDateFormat,datelbl); datefldP = (FieldType *)FrmGetObjectPtr(frmP,FrmGetObjectIndex(frmP, ServicePeriodDateField)); FldSetTextPtr(datefldP, datelbl); // Move start time to screen startTime = MemPtrNew(timeStringLength); (const Char*)startTime = CtlGetLabel(GetObjectPtr(ServicePeriodStartSelTrigger)); TimeToAscii(gCurrentRecord.start.hour, gCurrentRecord.start.minute,sysPrefs.timeFormat, startTime); startlbl = MemPtrNew(StrLen(startTime)+1); StrCopy(startlbl, startTime); CtlSetLabel(GetObjectPtr(ServicePeriodStartSelTrigger),startlbl); // Move end time to screen // If new record with no end time, use default label label; else end time if (gCurrentRecord.end.hour != noTime) { endTime = MemPtrNew(timeStringLength); (const Char*)endTime= CtlGetLabel(GetObjectPtr(ServicePeriodEndSelTrigger)); TimeToAscii(gCurrentRecord.end.hour, gCurrentRecord.end.minute,sysPrefs.timeFormat, endTime); endlbl = MemPtrNew(StrLen(endTime)+1); StrCopy(endlbl, endTime); CtlSetLabel(GetObjectPtr(ServicePeriodEndSelTrigger),endlbl); } MemHandleUnlock(currentRecordH); gNewRecord = false; } "David Fedor" <[EMAIL PROTECTED]> wrote in message news:72545@palm-dev-forum... > I'm pretty sure the problem is that you're calling TimeToAscii, putting the > results into endTime, but not making sure that endTime is a big enough > buffer to fit the time value... it is only as big as whatever was in the > trigger before. > > Do a MemPtrNew to allocate a buffer of at least "timeStringLength" bytes, > then call TimeToAscii, then call CtlSetLabel. More efficient and correct > too, how about that? :-) (Don't forget to free the memory that you > allocate, though...) > > -David Fedor > Palm, Inc. > > -- 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/
