Board index » delphi » How to locate Next with Locate?

How to locate Next with Locate?

Is there any smart way to use the facilities of Locate to find the Next
match to the criterias stated in Locate, when searching i tables. Or do
I need to switch approach and use Findkey/Goto or anything else that I
perhaps have missed?
Thanks,
Henrik Persson
 

Re:How to locate Next with Locate?


Henrick,
  you could use a filter (or range, if appropriate), then use First and Next
to iterate through the dataset.  (Locate only goes to the first record
mathcing the search criteria.)  An exmple would be:

mytable.filter := 'CompanyName = ''Widgets, Inc''';
mytable.filtered := true;
if not mytable.isempty then
begin
  mytable.first.
  while not mytable.eof do
  begin
    ...do something with the record...
    mytable.next;
  end;
end;

-Howard Moon

Re:How to locate Next with Locate?


On Fri, 26 Feb 1999 15:50:03 +0100, Henrik Persson

Quote
<henrik.pers...@halmstad.se> wrote:
>Is there any smart way to use the facilities of Locate to find the Next
>match to the criterias stated in Locate, when searching i tables. Or do
>I need to switch approach and use Findkey/Goto or anything else that I
>perhaps have missed?

Henrik,

Only if your current index is compatible with the criteria you use to
Locate, you can be confident that the next value will logically follow
the found value.  You still have to check that the value is within the
range that you expect though.

As a consequence, it is not advisable to rely on this behavior.
Better use SetRange or SetRangeStart/SetRangeEnd/ApplyRange if you can
use the current index or use a filter instead.

Hope this helps,

Jan

Re:How to locate Next with Locate?


If you want to find more than one record use SetRange or a Filter.

Bill

--
Bill Todd
(Sorry but TeamB cannot answer questions received via email)
(Remove nospam from my email address to contact me for any other reason)

Other Threads