Recent

Author Topic: does Locate have a next/prev funtion  (Read 5083 times)

WTDdallas

  • Full Member
  • ***
  • Posts: 100
does Locate have a next/prev funtion
« on: July 28, 2016, 05:21:40 pm »
I am doing a lookup in a dataset using Locate, Work great but, There are more that one entry that match the search.

Is there a way to do a locate.next or locate.prev ?

Handoko

  • Hero Member
  • *****
  • Posts: 5530
  • My goal: build my own game engine using Lazarus
Re: does Locate have a next/prev funtion
« Reply #1 on: July 28, 2016, 05:57:21 pm »
So far as I know TDBF.Locate doesn't support Next and Prev. But it can be achieved by using TStrings. Use Locate to get the results and save it to TString.

Other way to do it is to create your own Singly Linked List or Doubly Linked List data structure to store the results. It's probably the hardest way. But if you've done it, you'll be happy because you have programmed something that is very complicated.
 >:D

Thaddy

  • Hero Member
  • *****
  • Posts: 18961
  • Glad to be alive.
Re: does Locate have a next/prev funtion
« Reply #2 on: July 28, 2016, 05:57:49 pm »
Locate is standard - in its base functionality only - unidirectional so subsequent locate calls (depending on locate options, maybe increase recno by 1 in dbf) should find the next. Just try it.
If there is an index, though, locate uses the index and this scheme won't work.

Normally you would simply write an Sql  select query, but if that is not present?
« Last Edit: July 28, 2016, 06:07:22 pm by Thaddy »
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.

antelove19

  • Newbie
  • Posts: 1
Re: does Locate have a next/prev funtion
« Reply #3 on: July 28, 2016, 07:31:05 pm »
if ADOQuery1.Locate('time', timeday,[])  then
  begin
           DataModule1.ADOQuery1.MoveBy(1);
          //DataModule1.ADOQuery1.Next;
  end;

mangakissa

  • Hero Member
  • *****
  • Posts: 1131
Re: does Locate have a next/prev funtion
« Reply #4 on: August 03, 2016, 08:17:53 am »
dataset.MoveBy is doing the same as dataset.next
Lazarus 2.06 (64b) / FPC 3.0.4 / Windows 10
stucked on Delphi 10.3.1

mariodosreis

  • New Member
  • *
  • Posts: 16
Re: does Locate have a next/prev funtion
« Reply #5 on: August 24, 2016, 03:37:41 pm »
 Try this:
      //It works most of the times
      mykey:= #xyz ; // Some Key
      If tdDbf1.Locate... Then
       With tdDbf1 Do
        While ((tdDbf1.FieldByName('Key').As...=myKey) and Not (tdDbf1.Eof)) Do
        begin
         // If Index KEY is "Ascending"
          tdDbf1.Next;
         (// OR: If Index KEY is "Descending"
          tdDbf1.Previous ; ) // depending on what are your needs...
        end;
      You also have tbClientes.MoveBy(...); i don't know if it suit's your needs.  I gess not!?

I hope it help's
B.Regards
Mário

ahiggins

  • Jr. Member
  • **
  • Posts: 92
Re: does Locate have a next/prev funtion
« Reply #6 on: August 24, 2016, 06:34:36 pm »
What DB are you using?

if you are using TDbf then you could use a filter or SetRange (index required) then just use Next/Prev


kind regards

Tony

 

TinyPortal © 2005-2018