You have me a little confused...

Roberto Amorim wrote:
> typedef struct
> I'm trying the best way to add a record.
> 
> { Char *NrPed;
>   Char *CdMtv;
> } StruRegPed;

OK, so your StruRegPed structure consists of two pointers.

> Can I do this?:
> 
> iSize= StrLen(RegPed->NrPed)+1+StrLen(RegPed->CdMtv)+1
> hNewReg = DmNewRecord(PVPed, 0, iSize);
> reg=MemHandleLock(hNewReg);
> DmWrite(reg, 0 , RegPed , sizeof(iSize));

No.  Here, the DmWrite tries to write RegPed to a database record.  You
can't just write pointers (in RegPed) to a record.  You should write the
data they point at.

For example:
-----
char *myString = MemPtrNew(200) ;
StrPrintF(myString, "Some %s", "crap") ;

DmWrite(myRecord, 0, myString, StrLen(myString)) ;
-----

That code writes the data that myString points to, not the myString
pointer itself.

You want to replace the DmWrite call with something more like this:
DmWrite(reg, 0 , RegPed->NrPed , StrLen(RegPed->NrPed)+1); // will write
0 at end of string!
DmWrite(reg, StrLen(RegPed->NrPed)+1 , RegPed->CdMtv ,
StrLen(RegPed->CdMtv)+1); // will write 0 at end of string!

This will result in a record that looks like this:
 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|H|e|r|e| |i|s| |N|r|P|e|d|0|H|e|r|e|'|s| |C|d|M|t|v|0|
 - - - - - - - - - - - - - - - - - - - - - - - - - - -

The NrPed string is written first, then the CdMtv string is written
after it.  Both terminating 0's (ok \0 would not fit in my ascii diagram
:>) would be used to determine later how big each string is.  Your iSize
calculation is still very important when determining the size of the
entire record, for allocation purposes with DmNewRecord.

Another solution would be to fix the size of the two strings (e.g. Char
CdMtv[30]) so the entire StruRegPed could be written to a record in one
DmWrite call, because it would exist as one lump of data in memory
rather than being three lumps tied together with pointers.

Hope that helps,
Neek :)

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to