Subject Re: [IBO] FindIndex in OrderingLinks does not work
Author Helen Borrie
At 11:59 AM 3/11/2008, you wrote:
>Hi All,
> Has anyone been able to use the FindIndex function
>in TIB_StringList that is in TIB_Query?
> At present I want to be able to select a sorting
>field by program but the stringlist does not allow
>the function FindIndex because the list is not sorted.
>It crashes every time, of course.

It's not that the list "is not sorted" that is causing the AV. The Sorted property puts the strings into ascending alphanumeric order if true; otherwise their order will be simply arrival sequence. So - if the Sorted property is set, your IB_Stringlist's Name=Value strings will be in Name order, which will make FindIndex work faster. (Actually, I never sort stringlists in my own code: I load them from ib_cursors in the order I want them...)

All strings in stringlists are indexed, whereby the first string of the list has an index of 0 and the last has an index of the strings count - 1. FindIndex returns the index number (in the var) and True if the Name is found; otherwise it returns False and the initial Nil that you sent in the var.

But you'll get an AV if you try to apply such methods to an empty list. Make it a precaution with stringlists to test that the strings.Count > 0 before calling methods that refer to string objects. Maybe you're getting the AV on OrderingLinks because you haven't any OrderingItems defined.

BTW, to totally confuse us all, when you're mapping your OrderingLinks to OrderingItems, the first OrderingItem defined for a dataset is 1, not zero.