> Q: DmSeekRecordInCategory behavior.
> By Bryan [EMAIL PROTECTED]  12:52pm  
> I have a question about the behavior of DmSeekRecordInCategory.  
> Example: I have a DB with 10 records. Let's say I set every other record to a 
>category 1=Odd and the other records to 2=Even. Now, I position myself on record 
>index 3 (which is in the "Odd" category). Now, if I do:  
> DmSeekRecordInCategory( DB, &index, 1, dmSeekForward, 1);  
> I will get index=5 back. That's what I expect. But, do the same thing "out of 
>category" by passing in index=4 (the "Even" category), and I don't get 5 (which is 
>the "next" record in the "Odd" category). It appears that in order for the call to 
>work, the index that I pass in must also be in the same category that I am seeking. 
>Is this true? If so, why?  
> TIA 
> Bryan Nystrom 
> Natara Software, Inc. 

DmSeekRecordInCategory() is supposed to seek forward or backward in the
category. The index you supply is for a record that is either in the
category or not. If it's in the category, then going forward from it
puts you at the next record in the category, as you expect. If it's not,
then the fn will seek to the next (or previous) record IN THE CATEGORY
and then start seeking the number of records you want to move from
there.

I'm expecting you're getting index 7 in your second case, since
DmSeekRecordInCategory() starting at index 4 (even) and seeking forward
1 in the odd category will first find the next odd category record (5)
and then seek forward 1 from there (7).

You might want to use DmQueryNextInCategory() to find the closes record
in the category, if your current record is not in the category. If it is
in the caregory, use DmSeekRecordInCategory(). Something like this:

getNextInCat(DmOpenRef dbR, UInt index, Word category) {
UInt attr;

DmRecordInfo (dbR, index, &attr, NULL, NULL);
if ((attr & dmRecAttrCategoryMask) != category) 
   DmQueryNextInCategory(dbR, &index, category);
else
   DmSeekRecordInCategory(dbR,  &index, 1, dmSeekForward, category);

   // return index, or whatever you want to do here...
}

        
--

  John Schettino - http://members.tripod.com/schettino/
  CORBA For Dummies, AppleScript Applications, and more (Palm OS
Programming for Dummies? hmm, could be...)

Reply via email to