Hello,

Kind of a newbie question, I guess:  I'm trying to
write four strings into a record with four fields. 
I'm trying to iterate through these fields to write in
a loop, but everytime I believe I'm writing the
subsequent field, it always seems to be only writing
the first field.

Here's the essential lines of code:

typedef struct {
Char    Header1;
Char    Header2;
Char    Header3;
Char    Header4;
} HeaderType;

...

static void FirstFunction(){
  Char listString;
  for (n=0; n<=3; n++) {        
    listString = aValue[n]; //in reality, aValue is
pulled from a tSTL
    HeadWrite(n, listString);
}

static Err HeadWrite(Int8 fieldIndex, Char
*recordString ) {
  HeaderType *RecordP;
  MemHandle RecordH;
  Err error;

  RecordH = DmGetRecord(MyDB, 0);
  if (!RecordH) error=DmGetLastErr();
  else {
    RecordP = (HeaderType *) MemHandleLock(RecordH);
    switch (fieldIndex) {
      case 0:
        error = DmStrCopy(RecordP,
OffsetOf(HeaderType, Header1), recordString);
      break;
      case 1:
        ... //same as above, for Header2
      break;
      ... //and so on, through case 3/Header4
      //for the record, instead of this switch/case
      //method of iterating through the fields, I also
tried
      //to use DmStrCopy(RecordP, fieldIndex,
recordString); to
      //same results
    }
    
    MemHandleUnlock(RecordH);
    DmReleaseRecord(fortuneDB, 0, true);
  }
  MemPtrFree(index);
  return error;
}
  
###
I've used custom alerts to show me that it does seem
to go through the fields okay, but it also seems like
everytime ONE filed is written, ALL the fields are
overwritten with the same string.  But when I check
out the fields using PDBBrowser, it seems that only
the FIRST field is only ever written, and it's
overwritten everytime DmStrCopy is called, so that it
only reflects the last string in the loop.

I've tried a few different variations on this theme,
including writing to a copy of the record, then
rewriting the entire record with all of the fields,
but that didn't seem to work either.

Sigh.  Can y'all help?

Thanks!

Chris

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to