Solved

Locate Next using tbookmark problem.

Posted on 1998-04-22
4
599 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

20 Experts available now in Live!

Get 1:1 Help Now