This routine works fine in another program.  In another program it gets
called hundreds of times without complaint.  I am trying to use it in a
second program and the second time it is called the program blows up on
FldSetTextHandle.  The first time it goes through this logic it works fine,



void UpdateFieldStr(ULong newtime, ULong fieldname){
  FieldPtr fld;
  FormPtr frmP;
        VoidHand oldhand;
        VoidHand newhand;
        CharPtr fldptr;
        Int fldIndex;
        char temp[10];

        frmP = FrmGetActiveForm();
        fldIndex = FrmGetObjectIndex(frmP, fieldname);
        fld = FrmGetObjectPtr(frmP, fldIndex);
        oldhand = FldGetTextHandle(fld);
        newhand = MemHandleNew(11);
        fldptr = MemHandleLock(newhand);
        StrIToA(fldptr, newtime);
        switch(StrLen(fldptr)){
                case 0:
                        StrCopy(fldptr, "00");
                break;
                case 1:
                        StrCopy(temp, "0");
                        StrCat(temp, fldptr);
                        StrCopy(fldptr, temp);
                break;
                case 2:
                break;
                default:

                break;

        }
        MemPtrUnlock(fldptr);
        FldSetTextHandle(fld, newhand);
        FldDrawField(fld);
        if (oldhand) MemHandleFree(oldhand);

}

*****************************************************************

        This is the code that calls it.

        typedef struct {
                char field[20];
        } RecType;
    Boolean handled = false;
    FormPtr frmP;
    LocalID dbID;
    DmOpenRef StoreDB, CtrlDB;
    VoidHand RecordH;
    RecType temprecord;
    RecType *record;
    char mm[5], dd[5], yy[9], datestr[15];
                DateTimeType CurrentTime;
                ULong   CurrentSeconds;


    char storeno[5];


        switch (eventP->eType)
                {
                case menuEvent:
                        return MainFormDoCommand(eventP->data.menu.itemID);

                case frmOpenEvent:
                        frmP = FrmGetActiveForm();
                        MainFormInit( frmP);
                        FrmDrawForm ( frmP);
                        // Draw the parameters on the form

                        dbID = DmFindDatabase(0, "HHSTORE");
                        StoreDB = DmOpenDatabase(0, dbID, dmModeReadOnly);
                        RecordH = DmGetRecord(StoreDB, 0);
                        record = MemHandleLock(RecordH);
                        temprecord = *record;
                        StrCopy(storeno, temprecord.field);
                        MemHandleUnlock(RecordH);
                        DmReleaseRecord(StoreDB, 0, false);
                        DmCloseDatabase(StoreDB);
                        UpdateFieldStr(storeno, MainStorenoField);

                        dbID = DmFindDatabase(0, "HHCTRL");
                        CtrlDB = DmOpenDatabase(0, dbID, dmModeReadOnly);
                        RecordH = DmGetRecord(CtrlDB, 0);
                        record = MemHandleLock(RecordH);
                        temprecord = *record;
                        StrCopy(datestr, temprecord.field);
                        MemHandleUnlock(RecordH);
                        DmReleaseRecord(CtrlDB, 0, false);
                        DmCloseDatabase(CtrlDB);

                        mm[0] = datestr[0];
                        mm[1] = datestr[1];
                        mm[2] = '\0';
                        dd[0] = datestr[2];
                        dd[1] = datestr[3];
                        dd[2] = '\0';
                        yy[0] = datestr[6];
                        yy[1] = datestr[7];
                        yy[2] = '\0';

//                      it works ok up to here

                        UpdateFieldStr(mm, MainFilemmField);  <- this is where it 
blows up the
second time through
                        UpdateFieldStr(dd, MainFileddField);
                        UpdateFieldStr(yy, MainFileyyField);

                        CurrentSeconds = TimGetSeconds();
                        TimSecondsToDateTime(CurrentSeconds, &CurrentTime);
                        UpdateFieldTm((long) CurrentTime.month, MainTodaymmField);
                        UpdateFieldTm((long) CurrentTime.day, MainTodayddField);
                        UpdateFieldTm((long) CurrentTime.year, MainTodayyyField);


                        handled = true;
                        break;

                default:
                        break;

                }

        return handled;
}



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

Reply via email to