Mishael Kim wrote:
in the code below, i am just initializing 2 different boolean variables into the memory (trying to at least). do i just increment the recIndex by 1? (ie recIndex++) or does DmNewRecord take care of creating different memory allocations. I'm just worried that the second DmSet() will overwrite the first one, and not place it in a different spot.
//initialH = true initialH = DmNewRecord(gDB, &recIndex, recSize); if (initialH) { recP = MemHandleLock(initialH); DmSet(recP,0,true, 1); MemHandleUnlock(initialH); DmReleaseRecord(gDB, recIndex, true);}
//recIndex++; ??????
//authenticatedH = false
authenticatedH = DmNewRecord(gDB, &recIndex, recSize);
if (authenticatedH)
{ recP = MemHandleLock(authenticatedH);
DmSet(recP,0,false, 1);
MemHandleUnlock(authenticatedH);
DmReleaseRecord(gDB, recIndex, true);}
What you have done there looks fine. You don't have to worry about overwriting the first record because they are created in different parts of memory; different MemHandles.
One thing that you should keep in mind is that you are always referring to the same recIndex memory position, and the record will be created at that position in the database. So if recIndex is 4, then it will always insert the record at position 4, bumping all records that already have an index of 4 or greater. If you want the record to go at the end of the list, then set the index value to DmNumRecords(gDB), or use the macro "dmMaxRecordIndex" (as suggested by Manpreet) which (I'm guessing) does the same thing.
In order to test the successful write of those values you need to do a couple of things: find the record, and read the record. Finding may be tricky if you haven't paid attention to the order in which you have created the records, and if you haven't included some kind of index within the record itself to tell you which record is which. For example, your code created 2 records, and each is "recSize" in size, and only one byte has been written, a boolean. When you look through the records in the database you can find these records, but how do you know which is for "authenticated" and which is for "initial". You could choose to do this by record position, in which case you need to be VERY careful about the order when you create/delete/sort elements in the database. Or you could add an identifyer in the record itself, which is just another field with a unique value, so that you can always find which record has the info that you are looking for.
So, when you create the record, you could make the first byte equal to 1 if it is "initial" and 2 if it is "authenticated". Then, when you want to see if "authenticated" is set, search for the record whose first byte = 2, and see if the boolean value in that record is set. You'll probably need something a little more sophisticated than that, but this should give you the idea.
To read the value: 1. Find the record index (iterate through the records to find the right one) 2. Query the record: DmQueryRecord(gDB, recIndex); 3: Lock the record: with MemHandleLock 4. Look at the value 5. Unlock the record.
Bob.
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
