Druid,
It looks fine at first glance.
My only comments right now would be:
- after > labela = (Char *)CtlGetLabel( ctlP ); you should check labela
against null before using it. From memory it's possible for a popup
to have nothing selected in some circumstances.
- How does the GetFieldData() know to limit the data to 256? I would
have thought that this function would also need to be passed a
buffer length.
Aside from that it all looks sensible.
Chris Tutty
----- Original Message -----
From: "druid" <[EMAIL PROTECTED]>
To: "Palm Developer Forum" <[email protected]>
Sent: Tuesday, July 19, 2005 11:34 AM
Subject: Crash if I click button twice
> this code will crash If I click the save button twice
> I must not be releasing some memory somewhere
>
>
> static Boolean frmMain_saveButton_OnSelect(EventPtr event)
> {
> Char name[256];
> Char level[256];
> Char expFld[256];
> Char desc[256];
> FormType *frmP;
>
> ControlType *ctlP;
> Char *labela;
> Char labelb[256];
>
> frmP = FrmGetActiveForm();
>
> ctlP = FrmGetObjectPtr( frmP, FrmGetObjectIndex( frmP, frmPopupTrig1 ) );
> labela = (Char *)CtlGetLabel( ctlP );
> StrCopy(expFld, (const char *)labela);
>
> if(dbPtr == NULL)
> {
> // First see if we can find it:
> LocalID dbID = DmFindDatabase(DB_CARDNO, DB_NAME);
> if(!dbID)
> {
> // Couldn't find it, so create it:
> Err err = DmCreateDatabase(DB_CARDNO, DB_NAME, DB_CREATOR, DB_TYPE,
false);
> if(err)return err;
> // Now we ought to find it:
> dbID = DmFindDatabase(DB_CARDNO, DB_NAME);
> if(!dbID)return 1;
> }
> // Found it, now open it:
> dbPtr = DmOpenDatabase(DB_CARDNO, dbID, dmModeReadWrite);
> if(dbPtr == NULL)return 1;
> }
> // Everything went smoothly:
>
>
> GetFieldData( fldName, name );
> GetFieldData( fldLevel, level );
> GetFieldData( fldNewDesc, desc );
>
> size = StrLen(name)+1+ StrLen(level)+1+ StrLen(expFld)+1+
StrLen(desc)+1;
> index = dmMaxRecordIndex;
>
> h = DmNewRecord(dbPtr, &index, size);
> ptr = MemHandleLock(h);
> Offset = 0;
> DmWrite(ptr, Offset, (const void *)name, StrLen(name)+1);
> Offset += StrLen(name)+1;
> DmWrite(ptr, Offset, (const void *)level, StrLen(level)+1);
> Offset += StrLen(level)+1;
> DmWrite(ptr, Offset, (const void *)expFld, StrLen(expFld)+1);
> Offset += StrLen(expFld)+1;
> DmWrite(ptr, Offset, (const void *)desc, StrLen(desc)+1);
> MemHandleUnlock(h);
> DmReleaseRecord(dbPtr, index, true);
> err = DmCloseDatabase(dbPtr);
> return true;
> }
>
> --
> For information on using the PalmSource Developer Forums, or to
unsubscribe, please see http://www.palmos.com/dev/support/forums/
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/