Well, I just can't figure it out.  I'm simply writing a record to the
MemoPad database.  I got some code from the archives but it just doesn't
seem to work.  Attached is my code.  It writes the record and it looks okay
when I first bring up MemoPad but then when I attempt to access the record
in the MemoPad application, I receive a "Bad Record" error at statement
1678.  I've looked in the MemoPad code and on the Palm knowledgebase but
haven't found any answers or better examples of writing a MemPad record.
Any help would be greatly appreciated.

Dave

/***********************************************************************
 *
 * FUNCTION:    WriteMemoRecord
 *
 ***********************************************************************/
Err  WriteMemoRecord(Char * data)
{

        Ptr                     pRec;
        VoidHand        memoRec;
        Err                     error;
        UInt            mode;
        DmOpenRef       MemoPadDB;
        UInt32          memoPadDBType = 'DATA';
        UInt16          index;

        mode = dmModeReadWrite;

    MemoPadDB =  DmOpenDatabaseByTypeCreator(memoPadDBType, sysFileCMemo,
mode); //memoPadDBType is 'DATA'

        // Get index of new memo record to be added.
        index = DmNumRecords (MemoPadDB);

        // Create a new record in the database
        memoRec = DmNewRecord(MemoPadDB, &index, StrLen(data) + 1);

        // Lock down the block containing the new record.
        pRec = (Char*)MemHandleLock(memoRec);

        // Write record.
        error = DmWrite(pRec, 0, data, StrLen(data) + 1);
        if (error != 0)
                return error;

//      // Write null indicator to end of record.
//      error = DmWrite(pRec, StrLen(data), NULL, 1);
//      if (error != 0)
//              return error;

        // Unlock the block of the new record.
        error = MemPtrUnlock(pRec);
        if (error != 0)
                return error;

        error = DmReleaseRecord (MemoPadDB, 0, true);
        if (error != 0)
                return error;

        // Close the application's database.
        DmCloseDatabase(MemoPadDB);

        return noErr;

}


-- 
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