Del Ventruella wrote:

Is the corresponding load sequence:

void LoadData(DmOpenRef db, myStructType *myStructP){
   MemHandle   recH=NULL;
   UInt8      *recP;
   UInt16   recIndex=-1;  //will save the data in a new record at the
end of the database

   RecH=DmNewRecord(db, recIndex, sizeof(myStructType));
   if (recH){
       recP=MemHandleLock(recH);
       DmRead(recP,0,myStructP, sizeof(myStructType));
   }
}

?
Nope. You have to FIND the record first, and instead of the DmNewRecord (which CREATES a new database record) you will probably want to use a DmQueryRecord() command. When you save the record you will need to tag it with some kind of identifyer so that you can find it again. You could put an "id" field in your structure, or you could simply declare that 2 first bytes of the database record as an identifier (a UInt16 unique number), or you could just keep track of the record index in some other way (your preferences for the app?)

Once you have found the record you will then access it (DmQueryRecord, or DmGetRecord). Like so:
MemHandle   recH=DmQueryRecord(db, recIndex);

... then read the data. You can read the data directly, by assigning a pointer, of the same structure type, to the memory location where the stored data is. Like this:
myStructP=MemHandleLock(recH).

now you can access the saved structure data directly using that pointer.

One other question, the part about saving the pointer data.

The pointer contains the address of the data.

Under PalmOS, there is no hard drive where this data safely resides.
Well, databases are in storage memory, where they are 'safely' stored unless your battery loses power. Pointers are in dynamic memory, where they can be easily overwritten, unless you have left them locked..

If the address is overwritten, you lose the data.  Okay, that I understand.

How does one store (and load) this pointer data

in a manner that will insure that it is retained?
You would store the pointed-to information in your database, perhaps at the end of the structure, or as a separate record. There is no hard-and-fast rule as to how to do this.

I get the impression that what you need to do is to study some of the example code that is provided with the SDK and tools. These will be very instructive.

Bob.


--
For information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to