Something I do to delete db records until they are all gone is to keep
deleting the first record (the one with index = 0). That puts the PalmOS's
downward adjustment of remaining index values to work for you.

Mitch

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Robert
McKenzie
Sent: Thursday, April 27, 2000 9:47 AM
To: Palm Developer Forum
Subject: RE: Purging records problem


another error:

You are iterating FORWARD through the db and calling DmRemoveRecord.
DmRemoveRecord deletes this record and shifts all subsequent records
down (giving them one lower index), decreasing the total number of
records.  Thus you are quite likely to (1) skip records, since you
are iterating your index, and (2) call DmQueryRecord with an index
beyond the end of the database, resulting in "a fatal error message
if the index is out of range" (Palm OS SKD Reference, pg 493, ver 3.5,
preliminary modified 1/7/00).  If you must use DmQueryRecord, you
should walk the db from back to front...

-bob mckenzie
<[EMAIL PROTECTED]>

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
[EMAIL PROTECTED]
Sent: Thursday, April 27, 2000 1:20 AM
To: Palm Developer Forum
Subject: Purging records problem



Can anyone help find the error in the following code?? I've been staring at
it for days and can't work out what the problem is. I've looked at the purge
code in the ToDo app source code and can't see anything different.

The problem comes with the MemHandleLock...but I can't work out why.

TIA,

John.

void PurgeRecords (void)
{
    Word result;
    UInt i;
    UInt maxrecords;
    VoidHand recH = NULL;
    RecordTypePtr recP = NULL;
    TablePtr table;
    FormPtr form;


    result = FrmAlert(ConfirmPurge);
    if (result == 0)     //Change back to 0 to make work
    {
        //Purge
        form = FrmGetActiveForm();
        FrmSetFocus(form, noFocus);

        maxrecords = DmNumRecords (DB);
        if (! maxrecords) return;

        for (i = 0; i < maxrecords; i++)
        {
            recH = DmQueryRecord(IssueDB, i);
            if (recH == 0) continue;
            recP = (RecordTypePtr) MemHandleLock (recH);
            if (recP->completed = true)
            {
                MemHandleUnlock(recH);
                DmRemoveRecord(DB, i);
            }
            else
            {
                MemHandleUnlock(recH);
            }
        }
        FrmGotoForm(ViewTable);
    }
}




--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html


--
For information on using the Palm Developer Forums, or to unsubscribe,
please see http://www.palm.com/devzone/mailinglists.html



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to