下面是我写的一段程序,功能是差不多,但涉及到数据库,不过原理应该差不多吧:
procedure TForm3.Edit2Change(Sender: TObject);
var TempPos: integer;
begin
if BackSpacePressed then
Exit;
TempPos := Edit2.SelStart;
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('select * from illness_base where ILLNESS_NAME like ''%''+'''+Edit2.Text+'''+''%''');
Query1.Open;
if Query1.RecordCount>0 then
begin
Edit2.Text :=Query1.FieldByName('ILLNESS_NAME').AsString;
Edit2.SelStart := TempPos;
Edit2.SelLength := Length(Edit2.Text) - TempPos;
end;
end;
//BackSpacePressed是我定义的一个全局变量,当Backspace或者delete按下的时候为true,弹起的时候为false