Thanks Logan;
but i very confuse when i rewrite all the codes, the data can't be written into
database,please help;
codes:
//get record size
static UInt16 GetRecordSize (TestType *testPtr)
{
UInt16 size = 0;
if (!testPtr)
{
return size;
}
size = sizeof (TestType);
if (testPtr->name != NULL)
{
size += StrLen (testPtr->name) + 1;
}
if (testPtr->path != NULL)
{
size += StrLen (testPtr->path) + 1;
}
if (testPtr->testSubList != NULL)
{
size += (sizeof (UInt32)*4 + StrLen
(testPtr->testSubList->dbName) + 1)* testPtr->dbNum;
}
size += sizeof (FileRef);
size += sizeof (UInt32);
size += sizeof (UInt32);
return size;
}
//copy
static void CopyRecord(TestType *dstPtr, TestType * scrPtr)
{
UInt16 size = 0;
UInt32 offset = 0;
offset = 0;
if (scrPtr->name != NULL)
{
size = StrLen (scrPtr->name) + 1;
DmWrite(dstPtr, offset, scrPtr->name, size);
offset += size;
}
if (scrPtr->path != NULL)
{
size = StrLen (scrPtr->path) + 1;
DmWrite (dstPtr, offset, scrPtr->path, size);
offset += size;
}
size = sizeof (FileRef);
DmWrite (dstPtr, offset, &scrPtr->fileRef, size);
offset += size;
size = sizeof (UInt32);
DmWrite (dstPtr, offset, &scrPtr->fileSize, size);
offset += size;
size = sizeof (UInt32);
DmWrite (dstPtr, offset, &scrPtr->dbNum, size);
offset += size;
if (scrPtr->testSubList != NULL)
for (UInt16 i = 0; i < scrPtr->dbNum; i++)
{
size += StrLen (scrPtr->testSubList->dbName) + 1;
DmWrite (dstPtr, offset, scrPtr->testSubList->dbName, size);
offset += size;
size = sizeof (UInt32);
DmWrite (dstPtr, offset, &scrPtr->testSubList->dbCreator, size);
offset += size;
DmWrite (dstPtr, offset, &scrPtr->testSubList->dbType, size);
offset += size;
DmWrite (dstPtr, offset, &scrPtr->testSubList->dbSize, size);
offset += size;
DmWrite (dstPtr, offset, &scrPtr->testSubList->startPosition,
size);
}
}
//add record
static Err AddNewRecord(DmOpenRef dbP, TestType *testPtr, UInt16 *index)
{
MemHandle recordH;
TestType* recordP;
UInt16 newIndex;
Err err;
// Make a new chunk with the correct size.
UInt16 size = GetRecordSize (testPtr);
recordH = DmNewHandle (dbP, (UInt32) size);
if (recordH == NULL)
{
return dmErrMemError;
}
recordP = (TestType* )MemHandleLock (recordH);
// Copy the data from the unpacked record to the packed one.
CopyRecord(recordP, testPtr);
newIndex = FindSortPosition(dbP, recordP);
MemPtrUnlock (recordP);
err = DmAttachRecord(dbP, &newIndex, recordH, 0);
if (err)
{
MemHandleFree(recordH);
}
else
{
*index = newIndex;
}
return err;
}
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/