Carlos.

Here's the big deal, textH should exist as long as your text field so textH 
has to be a global or an arg to pass to your functions, so I'm guessing that 
you run this funtion on frmOpenEvent or on ctlSelectEvent (i.e. button tap), 
so you have to deal with it when you get an appStopEvent or before going to 
another form. You should set your text field handle to null and after doing 
this you should free your handle.

Also you have an error using FldSetTextHandle(), you should use it this way 
FldSetTextHandle (FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, 
MainFieldRisk)), textH).

 i.e.

MyRiskFormEventHandler (EventPtr event)
{
    Boolean handled = false;
    FormPtr frmP = FrmGetActiveForm();
    MemHandle textH;

    switch (event->eType)
    {
        case appStopEvent:
        {
            handled = FreeRisk(frmP, textH);
            break;
        }
        case frmOpenEvent:
        {
            FrmDrawForm(frmP);
            handled = CalculateRisk(textH);
            break;
        }
        case ctlSelectEvent:
        {
            switch (event->data.ctlSelect.controlID)
            {
                case MyRiskFormOKButton:
                {
                    handled = FreeRisk(frmP, textH);
                    FrmGotoForm(MyOtherForm);
                    break;
                }
            }
            break;
        }
    }
    return handled;
}

Boolean CalculateRisk (FormPtr frmP, MemHandle textH)
{
    ControlType* ctl;
    Boolean handled = true;
    char *str;
    double PI;

    PI += -1.236215274 - 2.598564382 - 2.119863737 ;
    PI = exp(PI);
    PI = (1.0 - pow(0.906,PI))* 100.0;
    textH = MemHandleNew(8);
    str = MemHandleLock(textH);
    doubleToStr(str, PI, 2);
    MemHandleUnlock(textH);
    FldSetTextHandle (FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, 
MainFieldRisk)), textH);
    FldDrawField(GetObjectPtr(MainFieldRisk));
    return handled;
}

Boolean FreeRisk (FormPtr frmP, MemHandle textH)
{
    Boolean handled = true;

    FldSetTextHandle(FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, 
MainFieldRisk)), NULL);
    MemHandleFree(textH);
    return handled;
}

Beware this code has not been compiler and or tested, and could contain 
errors. Just kidding.

Hope this helps you better.

Eduardo Orea.

"Carlos Gonzalez" <[EMAIL PROTECTED]> escribió en el mensaje 
news:[EMAIL PROTECTED]
> Eduardo thanks, this is my original code but, still giving me the same 
> error.. It alway gives the erro when I run it twice the function... the 
> second time gives me this error:.. MemoryMgr.c, Line 4384, Free Handle...
>
> ...
> PI += -1.236215274 - 2.598564382 - 2.119863737 ;
> PI = exp(PI);
> PI = (1.0 - pow(0.906,PI))* 100.0;
> textH = MemHandleNew(8);
> str = MemHandleLock(textH);
> doubleToStr(str, PI, 2);
> MemHandleUnlock(textH);
> FldSetTextHandle(GetObjectPtr(MainFieldRisk),textH);
> FldDrawField(GetObjectPtr(MainFieldRisk));
> MemHandleFree(textH);
> return handled;
> }
>
> Carlos
> 



-- 
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to