Hi,
I tried as per all of your suggestions. But its not
working. Please see the last part of the code. I am
trying to get values in the DB to a local structure
(sample). Iam getting ID value only. Name and address
are nulls. Please see the comments in the below code.
Thanks,
Raju
--- raju raya <[EMAIL PROTECTED]> wrote:
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
UInt32 mode= dmModeReadWrite;
UInt16 recordindex=0;
DmOpenRef dbRef;
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);
DmSet( p, offset, length , 0 );
DmWrite(p, offset, &x->ID, sizeof(x->ID));
offset+= sizeof(x->ID);
DmStrCopy(p, offset, (CharPtr) x->name);
//offset+= StrLen(x->name)+1;
DmSet( p, offset++, 1, 0 );
DmStrCopy(p, offset,(CharPtr)x->address);
DmSet( p, offset++, 1, 0 );
MemHandleUnlock(SampleRef);
}
}
//For verifying the record I tried the below code
Int16 numItems;
static DmOpenRef dbRef;
UInt32 mode= dmModeReadWrite;
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);
Details * 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 'sample' values. 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
>
__________________________________________________
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/