Actually you probably didn't show us the important part: What is pChar? I'm guessing it is not actually pointing to a chunk of memory, so your StrCopy is clobbering memory. A debugging session would tell you that.
Kevin -----Original Message----- From: Matt Andreko [mailto:[EMAIL PROTECTED] Sent: Friday, June 06, 2003 12:32 PM To: Palm Developer Forum Subject: problem writing to database (beginner) I have some code which just needs to write to a single table database. however, it's dying on a line, that i'm not sure how to fix. (i'm new to palm and c++) I've snipped most of the important parts here. It is dying on one of two lines, being: StrCopy(pChar, "Orders\0"); DmStrCopy(s, 0, pChar); can anyone help me figure out what would be happening? I have posted full source code at http://www.criminalsmostly.com/~mandreko/scanner.zip if it helps. typedef struct { char Department[20]; char Operator[20]; char RXNumber[20]; } DBRecord; typedef DBRecord DBRecordType; typedef DBRecord* DBRecordPtr; if (eventP->data.ctlEnter.controlID == Submit) { FormPtr pForm = FrmGetActiveForm(); if( pForm ) { //do clear code here FormPtr pForm = FrmGetActiveForm(); if( pForm ) { //TODO: put code to put database here SetFieldText(RX, "", 20, false); //Open a database, or create one if it doesn't exist Err err; //DmOpenRef myRef; // DB is being opened gDatabase = DmOpenDatabaseByTypeCreator( 'DATA', appFileCreator, dmModeReadWrite); if (!gDatabase) { // we're creating a new DB err = DmCreateDatabase(0, "ScannerORIM", appFileCreator, 'DATA', false); if (!err) { gDatabase = DmOpenDatabaseByTypeCreator('DATA', appFileCreator, dmModeReadWrite); if (!gDatabase) err = DmGetLastErr(); } } // Create a new record in the database UInt16 index = dmMaxRecordIndex; MemHandle h = DmNewRecord(gDatabase, &index, 5); if (!h) err = DmGetLastErr(); else { Char * s = (Char *) MemHandleLock(h); Char * pChar = (Char*)MemPtrNew(5 * sizeof(Char*)); StrCopy(pChar, "Orders\0"); // program is dying on next line DmStrCopy(s, 0, pChar); MemPtrFree( pChar); MemHandleUnlock(h); } CreateRecord(); if (gDatabase) DmCloseDatabase(gDatabase); FrmDrawForm(pForm); } handled = true; } //} if (eventP->data.ctlEnter.controlID == Clear) { FormPtr pForm = FrmGetActiveForm(); if( pForm ) { //do clear code here FormPtr pForm = FrmGetActiveForm(); if( pForm ) { SetFieldText(Dept, "", 20,false); SetFieldText(Oper, "", 20, false); SetFieldText(RX, "", 20, false); FrmDrawForm(pForm); } handled = true; } } static void CreateRecord() { MemHandle h; UInt16 index = 0; DBRecordType r; // this is our database record h = DmNewRecord(gDatabase, &index, sizeof(r)); // fill the record with data StrCopy(r.Department, "123456"); StrCopy(r.Operator, "987654321"); StrCopy(r.RXNumber, "147258369"); if (h) { // could fail due to insufficient memory! MemPtr p = MemHandleLock(h); Err err = DmWrite(p, 0, &r, sizeof(r)); MemPtrUnlock(p); DmReleaseRecord(gDatabase, index, true); } } -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/ ------------------------------------------ The information in this transmittal and any attachments are confidential and intended only for the recipient(s) listed above. You are hereby notified that any unauthorized distribution or copying of this transmittal or its attachments is prohibited. If you have received this transmittal in error, please notify invivodata immediately at (831) 438-9550. ------------------------------------------ -- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
