Solved

Locate Next using tbookmark problem.

Posted on 1998-04-22
4
602 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1336260
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
ID: 1336261
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
ID: 1336262
By the way Next; should not be their in the code.

Cheers Mike Ross.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1336263
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 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