Problem with Locate

I am using the Topaz library to manipulate .dbf format tables without using
the BDE.

I search an indexed field by entering the desired text into a TEdit box and
using the On Change event of the TEdit to reposition the file pointer using
the Locate command each time a character is entered. This is reflected in
the change of data displayed in a Topaz TTzGrid. When you press <Enter>
<Tab> or <Esc>, the On Key Down event shifts focus from the TEdit to the
TTzGrid. (See below for the code.)

When the app was first written this worked perfectly. As you type in, for
example, 'SMITH', the grid jumps to display last names beginning with S,
then SM, then SMI, etc. However, the longer I have worked with the data, the
more the following behaviour occurs:

Some names behave perfectly. You can type all the way to the end of the name
then press <Enter> to start working with the record you have located on the
grid. With other names, part way through typing, focus jumps to the grid. It
appears always to be the same names and always the same letter in that name.
Some names jump on the first letter, some on some other letter.

I have tried swapping the Topaz TTzGrid with a native Delphi TDBGrid but the
behaviour is the same. I have stepped through with the de{*word*81} but the
focus jump occurs with no indication of what causes it. I have considered
that it might be jumping where records have been deleted from the table, but
the app packs the table on closing and the same error occurs immediately
after restarting. It does not seem to correlate with such things as multiple
instances of the field value (eg. 4 Smiths in a row). I am not sure if the
problem lies with the Topaz TTzDbf component that handles the data table, or
with the Delphi TDataSource or with my code. Note that, although I have
specified loCaseInsensitive in the Locate Options, the Locate seems to
ignore this and so I have used some code to force an upper case initial

Sorry for the lengthy explanation, but after debugging and tearing my hair
out for weeks I am no closer to an answer.

---------- code 1 --------------------------------
procedure TForm1.Edit1Change(Sender: TObject);
  SearchOptions: TLocateOptions;
  cFieldName: String;
  If AppointmentButton.Down Then
    cFieldName := 'NextDate';
  If LastNameButton.Down Then
    cFieldName := 'Lname';
  If FirstNameButton.Down Then
    cFieldName := 'Fname';
  If CityButton.Down Then
    cFieldName := 'City';
  If PostCodeButton.Down Then
    cFieldName := 'Pcode';

  SearchOptions := [loCaseInsensitive, loPartialKey];

  If A2Klist.Locate(
    SearchOptions) = False Then


---------- end code 1 -----------------------------

---------- code 2 ----------------------------------
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
  Case Key of
    Chr(9) :
        ActiveControl := DbGrid1;
        ActiveControl := DbGrid1;
         ActiveControl := DbGrid1;
------------------- end code 2 ---------------------

Any help would be gratefully received.


Peter Lawrance
POSability Software
PO Box 3353 Mount Gambier SA 5290

Bite off more than you can chew - then chew like hell!