Hi Shital,

>   ctlP = FrmGetObjectPtr (frmPtr, FrmGetObjectIndex
> (frmPtr,PushButtonHour));
> timeP = MemPtrNew(4);
> timeP = CtlGetLabel(ctlP);

timeP is a pointer to the resource now, the MemPtrNew has
no effect (besides being a memory leak).

> CtlSetLabel(ctlP,timeP);
> MemPtrFree(timeP);

Hence you are trying to free the memory belonging to
the control here. Besides, the pointer passed to
CtlSetLabel must survive the function, as this function
does not make a copy of data (Palm OS 3.0 Manual, Vol. I,
Page 228).

I normally handle these things as follows:

CharPtr timeP = NULL; // global variable!

void function() {
        if( !timeP ) {
                timeP = MemPtrNew(...);
                ...initalize timeP
        }

        ...no calls to CtlGetLabel neccessary
        ...compute new contents in place

        CtlSetLabel( ctl, timeP );
        // this also notifies the GUI about a value change
}


Hope this helps,
        Holger Klawitter
--
Holger Klawitter                                     +49 (0)251 484 0637
[EMAIL PROTECTED]                             http://www.klawitter.de/


Reply via email to