I finally found a longstanding bug in my code which could cause my database
to be corrupted after hundreds of thousands of gremlins (arrrrrgh). Since a
similar bug is present in the Datebook, Address and Memo applications, I
suspect this is a fairly common problem, so I thought I would share it so
others don't spend days chasing the same thing.

The problem occurs when you use a category popup inside a details dialog.
Most people do something like this whenever the category trigger is hit:

   categoryEdited = CategorySelect (ToDoDB, FrmGetActiveForm (),
                DetailsCategoryTrigger, DetailsCategoryList,
                false, category, name, 1, 0);

The problem is that "categoryEdited" is typically a global variable which
is checked after the details dialog is dismissed. If the category trigger
is hit several times while the dialog is displayed, you only get the result
of the last hit. This can be disastrous if the trigger is hit once and the
Edit Categories item is used to delete a category and then it is hit a
second time to do an operation which produces no change.

The end result is that a category can be deleted and the application will
not realize it and continue to assign a no-longer-valid category number to
new records.

To demonstrate the error in the ToDo application, follow these steps:

   o  Create a new category "A".
   o  Create a new Todo item in category A.
   o  Set list view to display items in category A.
   o  Select item in category A and tap DETAILS.
   o  Tap category popup.
   o  Tap Edit Categories.
   o  Delete category A. (Tap YES in confirmation dialog)
   o  Tap OK to return to Details dialog.
   o  Tap category popup.
   o  Tap Edit Categories.
   o  Tap OK to return to Details dialog.
   o  Tap OK.
   o  Note that List view displays category "A" which no longer exists.
   o  Tap NEW to create a new item with text "Fail".
   o  Change list view to display All categories.
   o  The "Fail" note has been assigned to a category which does not exist.
   o  Select the "Fail" note and tap DETAILS.
   o  The category popup displays a blank category.

A related issue concerns the CANCEL button on the Details dialog. Although
most users would expect the CANCEL button to discard any changes made while
working in the details dialog, this may not be possible. The "Edit
Categories" item in the category popup can produce changes which are not
reversible, for example the deleting of a category or the merging of two
categories. Therefore, even if the user clicks the CANCEL button, you may
still have to process changes which were made to the categories.

Hope this saves other folks some time.

Bill Goodman
Cyclos


Reply via email to