Hi again,

Thanks, Scott-- though I think I messed up in my code
listing-- I didn't mean to imply that where:

listString = aValue[n];

that aValue[] was a character array-- I meant to say
that when going through the loop, aValue is one of 4
possible strings... that is, as my remark noted, a
each a different line from a string list resource...

So if I understand where you were going with checking
the length of the string to popluate the record, the
difference is that each field would hold a distinct
string.

So to repeat my code with edits, with hope you, or
someone else could comment in this regard (thanks =)
)...

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

...

static void FirstFunction(){
  Char listString;
  MemPtr strBuffer[4];
  for (n=0; n<=3; n++) {
    strBuffer[n] = MemPtrNew(80);
    listString =
SysStringByIndex(headStringListRes[position], n,
strBuffer[n], 80);
    HeadWrite(n, listString);
    }
    MemPtrFree(strBuffer[0]);
    MemPtrFree(strBuffer[1]);
    MemPtrFree(strBuffer[2]);
    MemPtrFree(strBuffer[3]);
}

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

--- In [EMAIL PROTECTED], "Grosch, Scott"
<[EMAIL PROTECTED]> wrote:
> > Kind of a newbie question, I guess:  I'm trying to
> > write four strings into a record with four fields.

> 
> Your example is confusing as you say you're writing
a string,
> yet your header is 4 characters.
> 
> If you're really writing strings (multiple
characters) to the
> database, then you need to do the DmGetRecord and
then loop
> over the length.  For example, if you want to write
the third
> string:
> 
> Char *str, *record;
> UInt16 offset;
> 
> h = DmGetRecord(db, idx);
> record = (Char *)MemHandleLock(h);
> 
> // Find how long the first string is.  Add one so
you skip over
> // the \0 which ends the string.
> offset = StrLen(record) + 1;
> 
> // Now move that far forward in the record
> record += offset;
> 
> // Find how long the second string is.
> offset += StrLen(record) + 1;
> 
> // Move over it as well
> record += offset;
> 
> // len is now the offset into the record of where to
write the
> // third string
> DmStrCopy(record, offset, "your new value");
> 
> 
> 
> Note that I'm not checking out of bounds conditions
here, and I've
> now corrupted the following records.  You basically
need to loop
> over it the first time and copy out the strings
(MemPtrNew()) into
> temp variables, then rewrite it entirely with all 4.
 You will
> likely have to resize your record as well.  If that
doesn't make
> sense mail back.
> 
> -- 
> For information on using the Palm Developer Forums,
or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

__________________________________________________
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