I have a structure that contains data entered from a form. I want to first put
data into that structure from an AppInfo block, although I don't know how to
determine if anyone has filled in the data yet. I have written a function to
put data into an AppInfo block, and it seems to run, but I get hardware error
#3 when I exit the program. I had it running with no errors before I decided
to store a structure in the appinfo block of the database.
I begin by putting data into the structure (Record is the name) that is used to
fill the fields on the form from a global structure variable (SiteInfo) that I
fill in with a fixed data set:
Record = *SiteInfo;
If someone pushes the "Save" button, I read the fields on the form and save the
results in Record. I then save the contents of Record in SiteInfo. SiteInfo
is the structure to which the function to write to the appinfo block looks for
the data to put in the appinfo block:
SiteInfo=*Record;
I then call the function to write to the appinfo block:
err = CreateAppInfoBlockForDB(gTransformer);
The function to write to the appinfo block is:
Err CreateAppInfoBlockForDB(DmOpenRef db)
{
UInt16 cardNo;
LocalID dbID;
MyAppInfo *appInfoP;
Err err;
MemHandle h;
//filled in by me
cardNo = 0;
dbID = '!!$g';
//end of filled in by me
TransformerDbaseCreate();
//DATABASE HAS TO BE OPEN!!! IT'S NOT OPEN TILL YOU OPEN THE TRANSFORMER FORM!!!
err = DmOpenDatabaseInfo(gTransformer, &dbID, NULL, NULL, &cardNo, NULL);
if (err !=errNone)
return err;
h = DmNewHandle(db, sizeof(MyAppInfo));
if (!h)
return dmErrMemError;
appInfoID = MemHandleToLocalID(h);
err= DmSetDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL,
NULL,&appInfoID, NULL, NULL, NULL);
if (err==errNone)
{
appInfoP = (MyAppInfo*)MemHandleLock(h);
//err = DmSet(appInfoP, 0, sizeof(MyAppInfo), 0);//clear all fields
err = DmWrite(appInfoP, 0, &SiteInfo, sizeof(SiteInfo));
MemPtrUnlock(appInfoP);
}
else
{
MemHandleFree(h);
}
err = DmCloseDatabase(gTransformer);
return err;
}
I need some way to always get the data in SiteInfo to correspond to what is in
the appinfo block, so I can always be sure that what is place into record and
loaded onto the form when the form is loaded is the saved data, even if the
user has left the application. To do this, I need to be able to determine if
there is anything in the appinfo block of a database, and if so, copy its
contents into the structure, Record. If not , I need to copy the contents of
the appinfo block into Record as they originally exist before the database is
created and the site data is saved using the "Save" button.
Can anyone show me how to:
1. Determine if the appinfo block has data in it?
2. Read the contents of the appinfo block into Record?
3. Save the contents of Record in the AppInfo Block?
I had been trying to set the SiteInfo pointer to Record to make sure that what
was in Record gets saved. I run into a problem when I try to close with the
following error. Otherwise, I get no errors when running the software. As I
said, I had no error messages before I attempted to add this appinfo block data:
"Hardware exception #3 occurred while th eemulator was calling the Palm OS
function "DmOpenDatabaseInfo". The emulator is now in an unstable state and
will reset."
Thanks for your help!
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/