I tried to run my application in POSE and I am getting a "just read
directly from  an unlocked memory chunk" error when I try to add new
records. I am attaching 2 functions and the record struct definition.
I get the error when I try to access the CTABRecord *recordstruct in the
function PackRecord. I can't understand what is causing this problem.
I appreciate any help anyone can offer.

Thanks,
Kourosh


typedef struct {
        CharPtr strCompany;
        CharPtr strAddress;
        CharPtr strCity;
        CharPtr strState;
        CharPtr strZip;
        CharPtr strCounty;
        CharPtr strPhone;
        CharPtr strFax;
        CharPtr strURL;
        CharPtr strFname;
        CharPtr strLname;
        CharPtr strEmail;
} CTABRecord;

static void NewFormAddRecord( )
{
        CTABRecord  newRecord;
        VoidHand    recHandle;
        
        UInt        index = 0;
        FormPtr     frm = FrmGetActiveForm();
        Boolean     recHasData = false;

        OpenOrCreateDatabase( 0 );

        //populates the new rec w/ form input
        recHasData |= PopulateDatabaseField( &newRecord.strCompany,
          EmployerNewCompanyField   );
        recHasData |= PopulateDatabaseField( &newRecord.strAddress,
          EmployerNewAddressField   );
        recHasData |= PopulateDatabaseField( &newRecord.strCity,
          EmployerNewCityField      );
        recHasData |= PopulateDatabaseField( &newRecord.strState,
          EmployerNewStateField     );
        recHasData |= PopulateDatabaseField( &newRecord.strZip,
          EmployerNewZIPField       );  
        recHasData |= PopulateDatabaseField( &newRecord.strCounty,
          EmployerNewCountyField    );
        recHasData |= PopulateDatabaseField( &newRecord.strPhone,
          EmployerNewPhoneField     );
        recHasData |= PopulateDatabaseField( &newRecord.strFax,
          EmployerNewFaxField       );
        recHasData |= PopulateDatabaseField( &newRecord.strURL,
          EmployerNewURLField       );
        recHasData |= PopulateDatabaseField( &newRecord.strFname,
          EmployerNewFirstNameField );
        recHasData |= PopulateDatabaseField( &newRecord.strLname,
          EmployerNewLastNameField  );
        recHasData |= PopulateDatabaseField( &newRecord.strEmail,
          EmployerNewEmailField     );


        // if the record is not empty insert it
        if ( recHasData ){
                recHandle = DmNewRecord(CTABDB, &index, sizeof(newRecord));

                if ( recHandle ) {
                        //write to DB
                        PackRecord( &newRecord, recHandle );            
                        //release the dirty record
                        DmReleaseRecord(CTABDB, index, true);
                }

        }
        
        CloseDatabase();
}

static void PackRecord(CTABRecord* recordstruct, VoidHand CTABDBEntry)
{
        CharPtr         s;
        UInt            offset = 0;

        s = (CharPtr) MemHandleLock(CTABDBEntry);

        //copy struct contents to db
        DmStrCopy( s, offset, (CharPtr) recordstruct->strCompany );
        offset += StrLen( recordstruct->strCompany ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strAddress );
        offset += StrLen( recordstruct->strAddress ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strCity );
        offset += StrLen( recordstruct->strCity ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strState );
        offset += StrLen( recordstruct->strState ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strZip );
        offset += StrLen( recordstruct->strZip ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strCounty );
        offset += StrLen( recordstruct->strCounty ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strPhone );
        offset += StrLen( recordstruct->strPhone ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strFax );
        offset += StrLen( recordstruct->strFax ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strURL );
        offset += StrLen( recordstruct->strURL ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strFname );
        offset += StrLen( recordstruct->strFname ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strLname );
        offset += StrLen( recordstruct->strLname ) + 1;
        DmStrCopy( s, offset, (CharPtr) recordstruct->strEmail );

        MemHandleUnlock(CTABDBEntry);
}



Reply via email to