I would check that the DmOpenDatabase calls are succeeding.
In particular, note that a database already opened for write access
can not be opened again (even by the same app) for write access.

-bob mckenzie

-----Original Message-----
From: Ed Lineberry [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 17, 2001 9:56 AM
To: Palm Developer Forum
Subject: Sort does not work consistently


I know I am missing something simple, but the more I look at this, the more
I can't understand why it doesn't work.

I have a DmCompareF function (see code at the bottom), and I call
DmQuickSort at three points in my application:  when a record is saved,
when the app is reset, and when the app receives SynchNotify.

It only sorts the database of reset.  The other occasions it does nothing.
What am I missing?

Below is all the relevant code I can think to include.  I don't know where
I stole the AppHandleReset and AppHandleSync from, but one at least seems
to work.

Any help would be appreciated.

- Ed


static void AppHandleReset(void)
{
     DmOpenRef dbTime;
     DmOpenRef dbProj;
     UInt16 mode;
     UInt16 err;


     // Find the application's data file.
     mode = dmModeReadWrite;
     dbTime = DmOpenDatabaseByTypeCreator(appDBType, appFileCreator, mode);
     if (!dbTime)
          return;
     err = DmQuickSort( dbTime, (DmComparF *) CompareTimesheet, 0);
     DmCloseDatabase(dbTime);

     dbProj = DmOpenDatabaseByTypeCreator(projectsDBType, appFileCreator,
mode);
     if (!dbProj)
          return;
     err = DmQuickSort( dbProj, (DmComparF *) CompareProject, 0);
     DmCloseDatabase(dbProj);
}

static void AppHandleSync(void)
{
     DmOpenRef dbTime;
     DmOpenRef dbProj;
     UInt16 mode;
     UInt16 err;


     // Find the application's data file.
     mode = dmModeReadWrite;
     dbTime = DmOpenDatabaseByTypeCreator(appDBType, appFileCreator, mode);
     if (!dbTime)
          return;
     err = DmQuickSort( dbTime, (DmComparF *) CompareTimesheet, 0);
     DmCloseDatabase(dbTime);

     dbProj = DmOpenDatabaseByTypeCreator(projectsDBType, appFileCreator,
mode);
     if (!dbProj)
          return;
     err = DmQuickSort( dbProj, (DmComparF *) CompareProject, 0);
     DmCloseDatabase(dbProj);

}

static int CompareTimesheet( PackedTimesheet *ts1, PackedTimesheet *ts2,
Int unusedInt, SortRecordInfoPtr unused1, SortRecordInfoPtr unused2,
VoidHand appInfoH )
{
     int result;

     result = (ts1->date < ts2->date);

     return result;
}

/
UInt32 PilotMain( UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
{
     Err error;

     error = RomVersionCompatible(version20, launchFlags);
     if (error)
          return error;

     switch (cmd) {
          case sysAppLaunchCmdNormalLaunch:
[snip]

          case sysAppLaunchCmdSyncNotify:
               AppHandleSync();
               break;

          case sysAppLaunchCmdSaveData:
               FrmSaveAllForms();
               break;

          case sysAppLaunchCmdInitDatabase:
               break;

          case sysAppLaunchCmdSystemReset:
               AppHandleReset();
               break;

          default:
               break;
     }
     return 0;
}




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

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

Reply via email to