Examples

Removing an Entry While a Cursor Is Iterating

Question:
What happens to a cursor when an entry is removed?

Answer:
The cursor just skips over any of the entries that had been in the soup. If the current entry happens to be at the removed entry, then cursor:Entry() returns the symbol 'deleted.

Here is how you can observe the behavior (a QuickTime movie of this example is available). Execute the following code from the Inspector that finds the first entry:

soup := GetUnionSoup("Names");
curs := soup:Query(nil);
e := curs:Entry();
Print(curs:Entry());
{
   sortOn: ...
   ...
}
Print(e);
{
   sortOn: ...
   ...
}
Now, remove the entry and execute the Print statement again:

EntryRemoveFromSoup(curs:Entry();
Print(curs:Entry())
deleted
Print(e);
{
   sortOn: ...
   ...
}
The code you write in your application should always consider the fact that Entry may return deleted.


An online version of Programming for the Newton using Macintosh, 2nd ed. ©1996, 1994, Julie McKeehan and Neil Rhodes.

Last modified: 1 DEC 1996