1) mode is not set in your example
2) looks like a C pointer vs string problem
This assigns a char pointer to a struct.
newRecord.body = NewFile;
This copies the string pointed to by the same char pointer (if that's what
you wanted).
StrCopy( newRecord.body, NewFile );
You then need to increase the size to allocate by length of string.
Otherwise if you just want a pointer in the struct,
you need to make sure the pointer is valid later on when you want to read
that record.
For simplicity, database records that are self contained
are easier to manage than those with pointer(s) in them.
Regards,
Randy Maxwell
-----Original Message-----
From: Ender Wiggin [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 26, 2001 4:51 PM
To: Palm Developer Forum
Subject: NULL Pointer
Why does the following code result in my MemHandle newRecordH being equal to
0x00000000? and ultimately throwing an exception?
#include "AddToDB.h"
#define DBType 'DATA'
#define CreatorID 'IDPT'
#define DBName "LSDB"
DmOpenRef glibDB;
Err error = 0;
UInt16 index = 0;
UInt16 mode;
Err InitDB()
{
glibDB = DmOpenDatabaseByTypeCreator(DBType,CreatorID,mode);
if (!glibDB)
{
error = DmCreateDatabase(0,DBName,CreatorID,DBType,false);
if (error)
return error;
glibDB = DmOpenDatabaseByTypeCreator(DBType,CreatorID,mode);
if (!glibDB)
return DmGetLastErr();
}
return error;
}
void AddTextFileToDB(char* NewFile)
{
TextFile newRecord;
MemHandle newRecordH;
TextFile* newRecordP;
newRecord.body = NewFile;
newRecordH = DmNewRecord(glibDB,&index,sizeof(newRecord)); //Error
Line!!!!!!!
newRecordP = (TextFile*)MemHandleLock(newRecordH);
DmWrite(newRecordP,0,&newRecord,sizeof(newRecord));
MemHandleUnlock(newRecordH);
DmReleaseRecord(glibDB,index,false);
++index;
}
--
Thanks in advance
--
Nikue Harlley
Veni Vidi Vici
--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/tech/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/