Hi all.

I have been trying to figure this one out for a while not. Here's my
code.static Boolean 

NewJobFormHandleEvent (EventPtr event)
{
        Boolean         handled = false;
        FormPtr         frm;  //form pointer
        FieldPtr    custfld,namefld,phonefld,contactfld;
        VoidHand    txth;
        UInt        pos;
        Err         e;

   CALLBACK_PROLOGUE

        
   switch (event->eType)
   {
        case ctlSelectEvent:  
                switch (event->data.ctlEnter.controlID)
                   {
                   case donebutton:
            frm = FrmGetActiveForm();
                // save data new record
                EditMode = false;
            custfld =
FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,customername));
            unpackeddata.fields[icustomer] = FldGetTextPtr(custfld);
            namefld =
FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,jobname));
            unpackeddata.fields[iname] = FldGetTextPtr(namefld);
            contactfld =
FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,contact));
            unpackeddata.fields[icontact] = FldGetTextPtr(contactfld);
            phonefld =
FrmGetObjectPtr(frm,FrmGetObjectIndex(frm,phone));
            unpackeddata.fields[iphone] = FldGetTextPtr(phonefld);
        unpackeddata.fields[inumber] = NULL;
        unpackeddata.fields[istatus] = NULL;           
// Works fine to here. data is transfered into array of charptr's just
fine. Then I call jobnew record...


            pos = 0;
            e = JobNewRecord(JobTrackerListDb,&unpackeddata,&pos);
                FrmGotoForm(joblistform);       
                break;
                   }
            break;


UInt JobUnpackedSize(JobListDataPtr r)
{
   UInt size;
   Int   index;
   
// size = sizeof (PackedJobListData) - sizeof (char);   // takes
account of first fields
   for (index = FirstJobField; index < JobFieldCount; index++)
      {
      if (r->fields[index] != NULL)
         size += StrLen(r->fields[index]) + 1;
      }
   return size;
}


Err JobNewRecord(DmOpenRef dbP, JobListDataPtr r, UInt *index)
{
   VoidHand             recordH;
   Err                   err;
   VoidPtr   recordP;
   UInt                   newIndex;
   Long size;
   CharPtr  s;

// for some reason, the next call isn't returning any size. I check in
the routine, and the size is right, but it doesn't return??

   size = JobUnpackedSize(r);
   recordH = DmNewHandle(dbP,size );
   if (recordH == NULL)
      return dmErrMemError;

   recordP = MemHandleLock(recordH);
   if (recordP == NULL) ErrDisplay("locked handle but invalid"); 
//this error doesn't show up
   JobListPack(recordP,r);   //dest src
...

static void JobListPack(VoidPtr dest,
                     JobListDataPtr src)
{
        JobListDataFlags        flags = 0;
        UInt    size;
        ULong   offset = 0;
        CharPtr srcP;
        Int   index;
        UInt  len;
        
        offset =+ sizeof(JobListDataFlags);
   for (index = FirstJobField; index < JobFieldCount; index++) {
      if (src->fields[index] != NULL)
         {
         ErrFatalDisplayIf(src->fields[index][0] == '\0' , 
            "Empty field being added");
         srcP = src->fields[index];
         len = StrLen(srcP) + 1;
         DmWrite(dest, offset, srcP, len);
// get an error here, "DmWriteCheck failed"
         offset += len;
         SetBitMacro(flags, index);
         }
      }
        DmWrite(dest, 0, &flags, sizeof(flags));
}

The unpackedjobdata is an instance of a struct with an array of
charptr's. No rocket science.

Something is getting corrupted somewhere, and darned if I can figure it
out. Is the way I am getting the fielddata into my charptr right?
FldGetTextPtr returns a charptr, doesn't it? All I do prior to this
code is show a form with 4 fields in it, with a done button at the
bottom. Any help at all? The database code is copied mostly from the
addressbook example. I use GCC.

Thanks

Derek
__________________________________________________
Do You Yahoo!?
Bid and sell for free at http://auctions.yahoo.com

Reply via email to