try this code
procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState
);
var
i: integer;
tempStr: String;
found: Boolean;
begin
Caption := Edit1.Text;
try
found := false;
for i := 0 to ListBox1.Items.Count - 1 do
begin
//ShowMessage(picListBox.Items[i]);
if(AnsiStartsText(Edit1.Text, ListBox1.Items[i]) = True) then
begin
ListBox1.ItemIndex := i;
ListBox1.TopIndex := ListBox1.ItemIndex;
found := true;
Caption := Caption +' '+IntToStr(i);
break;
end;
end;
finally
if (not found) then
begin
//MakeBeep; // Alert user
tempStr := Edit1.Text;
delete(tempStr, Length(tempStr), 1); // remove unmatching char
Edit1.Text := tempStr;
end;
end;
end;