now,i make a simple test.there are two functions, AddNewRecord1 add a record
into database ,that contain a structure"TempType" , AddNewRecord2 do that like
AddNewRecord1, but it only contains a base type "Char";the result is that
AddNewRecord1 add record is unsuccessful,but AddNewRecord12 succeed!
what a result!
please help,thanks!
the functions:
static Err AddNewRecord1(DmOpenRef dbP, UInt16 *index)
{
MemHandle recordH;
UInt16 newIndex;
Err err;
typedef struct
{
Char * name;
}TempType;
TempType* recordP;
TempType temp;
temp.name = "a test now";
newIndex = DmNumRecords (dbP);
// Make a new chunk with the correct size.
UInt16 size1 = StrLen (temp.name) + 1;
recordH = DmNewHandle (dbP, (UInt32) (size1));
if (recordH == NULL)
{
return dmErrMemError;
}
recordP = (TempType* )MemHandleLock (recordH);
DmWrite (recordP, 0, temp.name, size1);
MemPtrUnlock (recordP);
err = DmAttachRecord(dbP, &newIndex, recordH, 0);
if (err)
{
MemHandleFree(recordH);
}
else
{
*index = newIndex;
}
return err;
}
static Err AddNewRecord2(DmOpenRef dbP, UInt16 *index)
{
MemHandle recordH;
UInt16 newIndex;
Err err;
Char * name;
Char* recordP;
name = "a test now";
newIndex = DmNumRecords (dbP);
// Make a new chunk with the correct size.
UInt16 size1 = StrLen (name) + 1;
recordH = DmNewHandle (dbP, (UInt32) (size1));
if (recordH == NULL)
{
return dmErrMemError;
}
recordP = (Char* )MemHandleLock (recordH);
DmWrite (recordP, 0, name, size1);
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/