raju raya wrote:
>
> typedef struct
> {
> unsigned int ID;
> const char * name;
> const char * address;
>
> }Details;
> typedef struct
> {
> unsigned int ID;
> char name[1];
>
>
> }PackDetails;
>
> //writing record to database
> DmCreateDatabase(0, "MySampleDB1", 'myd1','res1',false);
>
> DmOpenRef dbRef = DmOpenDatabaseByTypeCreator('res1','myd1',mode);
> UInt16 index=0;
> VoidHand h = DmNewRecord(dbRef,&index, 1);
> Details r1 ={1,"a1","d1"};
> PackDetailsRecord(h, &r1);
> DmReleaseRecord(dbRef, index, true);
> DmCloseDatabase(dbRef);
>
> //end. after this I checked using Insider tool.
> //its not showing character data. But its showing
> //the ID properly.
>
> static void PackDetailsRecord(VoidHand
> SampleRef,Details *x )
> {
> UInt32 length =0;
> void *p;
> unsigned long offset =0;
> length =
> sizeof(x->ID)+StrLen(x->name)+StrLen(x->address)+2;
>
> if (MemHandleResize(SampleRef,length)==0)
> {
> p= MemHandleLock(SampleRef);
>
> DmWrite(p, offset, &x->ID, sizeof(x->ID));
> offset+= sizeof(x->ID);
> DmStrCopy(p, offset, (CharPtr)& x->name);
> offset+= StrLen(x->name)+1;
> DmStrCopy(p, offset,(CharPtr)&x->address);
> MemHandleUnlock(SampleRef);
> }
> }
The docs say that DmCreateDatabase, DmOpenDatabaseByTypeCreator,
DmNewRecord, DmReleaseRecord, DmCloseDatabase, MemHandleResize, DmWrite,
DmStrCopy and MemHandleUnlock all can fail. You should check for each of
these cases before going on.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/