Subject Re: FindIndex in OrderingLinks does not work
Author Steve Fields
--- In IBObjects@yahoogroups.com, Helen Borrie <helebor@...> wrote:
>
> 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.
>
> Helen
>

I tried and put a sorted := true in and it works fine.

What I really needed was a way to link a TIB_Grid with
a TIB_IncSearch so that when I clicked on a column to
sort the table it would cause the search field to
reflect the new OrderingLink fieldname.

How I actually arrived at a workable plan is the following
in the OnTitleClick of the grid associated with the search
field:

srchField.OrderingLink :=
TIB_Column(TheGrid.BuffFields[ACol - 1]).FieldName;

Thanks much Helen,
Steve