Hi,
I am trying very simple thing writing a record and
just displaying it. But the following code is not
wokring. Can any body tell what's the problem in this
code.
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);
}
}
//For verifying the record I tried te below code
dbRef=
DmOpenDatabaseByTypeCreator('res1','myd1',mode);
numItems = DmNumRecordsInCategory( dbRef,
dmAllCategories );
for ( Int16 ndx = 0; ndx < numItems; ndx++ )
{
MemHandle h = DmGetRecord( dbRef, ndx );
PackDetails * P;
P= (PackDetails *)MemHandleLock(h);
const char * s= (P->name);
RestaurantDetails * sample = (Details
*)MemPtrNew(sizeof(Details));
sample->ID= P->ID;
sample->name = s;
s+= StrLen(s)+1;
sample->address = s;
MemPtrFree( sample) ;
MemHandleUnlock(h);
}
DmCloseDatabase(dbRef);
// I checked in debugger. Only ID am getting properly.
//for name and address I am getting nulls.
Thans in advance,
Raju
__________________________________________________
Do You Yahoo!?
Send your FREE holiday greetings online!
http://greetings.yahoo.com
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/