> From: [EMAIL PROTECTED]
>
> We have read the docs and we have a question on how
> o save the text in our field. This is our code.
>
> gDb=DmOpenDatabaseByTypeCreator(yourdbtype,yourapptype,dmModeReadWrite);
> if(! gDb)
> DmCreateDatabase(0,yourdbname,yourapptype,yourdbtype,false);
> DmOpenDatabaseInfo(gDb,&theLocalID,NULL,NULL,&theCardNum,NULL);
>
If you can't open the db, then you create it but don't open it. Then you
try to get info on the open database regardless of whether or not you opened
it. Bad logic. Also, both DmCreateDatabase and DmOpenDatabaseInfo return
an Err, which you don't check.
> DmDatabaseInfo(theCardNum,theLocalID,NULL,&theAttributes,
> NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
If DmOpenDatabaseInfo failed, then theLocalID won't have the right value.
> theAttributes |= dmHdrAttrBackup;
> theCardNum=0;
> DmSetDatabaseInfo(theCardNum,theLocalID,NULL,&theAttributes,
> NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
Again, you aren't testing the returned error code of these functions. After
passing through the preceding bad code, I wouldn't be surprised if these
fail, too.
FYI, here is Neil Rhodes' sample code for opening a database (from "Palm
Programming: the Developer's Guide," available free online:
----------------
// Find the Customer database. If it doesn't exist, create it.
gDB = DmOpenDatabaseByTypeCreator(kCustType, kSalesCreator, mode);
if (! gDB) {
err = DmCreateDatabase(0, kCustName, kSalesCreator,
kCustType, false);
if (err)
return err;
gDB = DmOpenDatabaseByTypeCreator(kCustType, kSalesCreator, mode);
if (!gDB)
return DmGetLastErr();
// code to initialize records and application info
}
----------------
> if (adding)
> {
> myRecordHandle=DmNewRecord(gDb, &RecordIndex, sizeof(newRecord));
Here you created a new record, marked it as busy, and got a handle to it.
Again, you don't check for any errors.
> newRecordPtr=(OurStruct *)MemHandleLock(myRecordHandle);
> newRecord.cost=Coster;
> newRecord.serialnum=Serial;
> newRecord.datefield=Dater;
> newRecord.itemname=Namer;
> newRecord.lin=Lin;
> newRecord.nsn=Nsn;
> DmWrite(newRecordPtr,0,&newRecord,sizeof(newRecord));
The line above copes the data in newRecord to the record pointed to by
newRecordPtr.
> DmWrite(newRecordPtr,0,(CharPtr)
&newRecord->serialnum,sizeof(newRecord));
Now, this line copies sizeof(newRecord) bytes from newRecord to the record
pointed to by newRecordPtr, but it starts writing from the serialnum member
of newRecord. I don't know why you are starting the write at
newRecord.serialnum. You want to write out the entire newRecord structure,
which is what you already attempted in the preceding line.
> MemHandleUnlock(myRecordHandle);
>
As you can see, there is quite a lot wrong with this small section of code.
(Probably even more errors than I noticed.) If the rest of your app has
this many problems, then you really do need help. We can't write all of
your code for you. Read all of the Palm docs (see
http://www.palmos.com/dev/tech/docs/) and read two or three books on Palm
programming, try to create programs that use their example code, and look at
the source code for the built in apps and try to understand how they work.
Then maybe you'll have more luck writing your own apps.
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/