Solved

Locate Next using tbookmark problem.

Posted on 1998-04-22
4
597 Views
Last Modified: 2012-05-04
I am having a problem with Locating a second occurance of lets say 'Mike' in a field called 'finder'.
I am using the following code to find the first occurance no problem:-

TABLE1.LOCATE ('Finder', EDIT1.TEXT,  [loCaseinsensitive, loPartialKey]);

This works no problem. My problem starts with trying to locate the next occurance of what ever is in the 'Edit1.Text'
This is what I am doing:-

procedure TForm3.BitBtn4Click(Sender: TObject);
begin
 If not Table1.Active then Exit;
If Table1.FieldDefs.IndexOf( 'Finder' ) < 0 then Exit;
bmPos := Table1.GetBookMark;
With Table1 do
begin
DisableControls;
First;
begin
Table1.GotoBookMark( bmPos);
TABLE1.LOCATE ('Finder', EDIT1.TEXT,  [loCaseinsensitive, loPartialKey]);
end;
Next;
end ;
Table1.FreeBookMark( bmPos );
Table1.EnableControls;
end;

This just goes to the next record in the field for some reason.
I Know this can work as for some funny reason it worked twice then refused to work again. I did some editing and cant remember exactly how I did it.
Can someone please help soon.
michael.ross@cableinet.co.uk
Cheers
Mike Ross
0
Comment
Question by:pedro1
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
Comment Utility
Hi Pedro,

procedure TForm3.BitBtn4Click(Sender: TObject);
    begin
         If not Table1.Active then Exit;
         If Table1.FieldDefs.IndexOf( 'Finder' ) < 0 then Exit;

    bmPos := Table1.GetBookMark;

    With Table1 do
    begin
     DisableControls;
     First;
     begin ------------------------------------------------------- ???????????
       Table1.GotoBookMark( bmPos);
       TABLE1.LOCATE ('Finder', EDIT1.TEXT,  [loCaseinsensitive, loPartialKey]);
     end; ----------------------------------------------------------???????????
    Next;
   end ;
   Table1.FreeBookMark( bmPos );
   Table1.EnableControls;
  end;

I think your code is always doing a locate and then moves to the next record!!!!
Why have you declared a begin and end (between gotobookmark & locate), I think you've removed some important lines here!!!!

This does your code now

Stores position,
goes to first record,
goes to stored record,
does a locate
goes to next record
frees bookmark.

Hope I didn't overlooked something, it's still early in the morning for me.

Regards, ZiF.
0
 

Author Comment

by:pedro1
Comment Utility
You are right That my code does not need a begin or an end at those points. For some reason though the locate is not starting from the bookmark that I have set. It is always locating from the beginning of the field and moving the cursor to the record that I have already located previously. Is there a way to use locate so that it starts locating from the bookmark that I have set, so that it will find the next occurance of whatever Im looking for in this field.
Cheers Mike Ross
0
 

Author Comment

by:pedro1
Comment Utility
By the way Next; should not be their in the code.

Cheers Mike Ross.
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi Mike,

Locate is designed for finding the 1st record matching the search criteria, So it will ALWAYS start from the first record of the table.

Instead you could use the functions FindFirst and then FindNext.

Regards, ZiF.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now