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
Solved

Locate Next using tbookmark problem.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 76
Convert GUI app into console app for Win32 Env 5 109
LAN or WAN ? 11 95
Base1 Encode/Decode 3 82
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

837 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