Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 611
  • Last Modified:

Locate Next using tbookmark problem.

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
pedro1
Asked:
pedro1
  • 2
  • 2
1 Solution
 
ZifNabCommented:
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
 
pedro1Author Commented:
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
 
pedro1Author Commented:
By the way Next; should not be their in the code.

Cheers Mike Ross.
0
 
ZifNabCommented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now