Hi
I have a simple but nasty prob. Whenever, i create and open a
database and insert records into it, everything is fine. I am able
to read the records and display them. But when i exit the
application and again run it, the records are not being read. The
number of records stored is correct but i can find only junk in
the records. Can someone explain the cause. The code snippet is
reproduced below.
The records in the database go into a list. This is done correctly
when the database is created for the first time. But when it is
closed and opened, the records seem to have vanished into thin
air. The same error occurs even when i try to insert a new record
into the open database. The record is succefully saved at index 0,
but is not retrieved. This kind of error does not occur when the
database is created and opened.
Thanks in advance for the help.
-------------------------
void CreateOrOpenMyMainDB(DmOpenRef &dbMainRef,int& retcode)
{
// Find My's main database. If it does not exist create it.
dbMainRef = DmOpenDatabaseByTypeCreator(MyDBMainType,
MyCreatorID,
mode);
if(!dbMainRef)
{
// Create a record database, last param is false
error = DmCreateDatabase(0, MyDBMainName, MyCreatorID,
MyDBMainType, false);
if(error)
{
retcode = -1; // unable to create database
return;
}
dbMainRef = DmOpenDatabaseByTypeCreator(MyDBMainType,
MyCreatorID, mode);
if(!dbMainRef)
{
retcode = -2; // Unable to open database
return;
}
else
{
retcode = 0; // Successfully created and opened the
//database
return;
}
}
else
{
retcode = 1; // Successfully opened the database
return;
}
}
Code used to save the records
Boolean CreateNewMainDBRec(DmOpenRef &dbMainRef, Maindbrec
&DBRec)
{
UInt16 recAt = 0;
Err myerr;
MemHandle h = DmNewRecord(dbMainRef, &recAt,
sizeof(Maindbrec));
Maindbrec *recP = (Maindbrec*)MemHandleLock(h);
myerr = DmWrite(recP, 0, &DBRec, sizeof(DBRec));
MemHandleUnlock(h);
DmReleaseRecord(dbMainRef, recAt, true);
if(myerr == errNone)
return true;
else
return false;
}
The code used to populate the lists
numrecs = GetNumRecs(dbMainRef);
numrecs = (numrecs <= 4)?numrecs:4;
if(numrecs)
{
Char **filelist;
Char **bnamelist;
MemHandle recordH, hand;
UInt16 i;
filelist = (Char**)MemPtrNew(4 * sizeof(Char*)); // Max no
of recs
//limited to 4
gFileListElements = filelist;
gFileListNumItems = numrecs;
bnamelist = (Char**)MemPtrNew(4 * sizeof(Char*));
gBNameListElements = bnamelist;
gBNameListNumItems = numrecs;
for(i = 0; i < numrecs; i++)
{
recordH = DmQueryRecord(dbMainRef, i);
MyRecType = (Maindbrec*)MemHandleLock(recordH);
hand = MemPtrRecoverHandle((MemPtr)MyRecType->fileno);
MemHandleLock(hand);
filelist[i] = (Char*)MemPtrNew(20);
StrCopy(filelist[i], MyRecType->fileno); //str);
MemHandleUnlock(hand);
hand =
MemPtrRecoverHandle((MemPtr)MyRecType->borrowername);
MemHandleLock(hand);
bnamelist[i] = (Char*)MemPtrNew(50);
StrCopy(bnamelist[i], MyRecType->borrowername);
MemHandleUnlock(hand);
MemHandleUnlock(recordH);
}// end of for(i = 0 to numrecs-1)
for(i = numrecs; i < 4; i++)
{
filelist[i] = (Char*)MemPtrNew(20);
filelist[i] = "<>";
bnamelist[i] = (Char*)MemPtrNew(50);
bnamelist[i] = "<>";
}
// Set the list choices
LstSetListChoices(lstFileNo, filelist, 4);
LstSetListChoices(lstBName, bnamelist, 4);
} // end of if(numrecs)
-----------------------------
Any help would be highly appreciated.
Sridhar
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/