刚贴的是错误的,这段测试并通过。要在edit的keyup事件中处理。<br><br>procedure TForm1.Edit1KeyUp(Sender: TObject; var Key: Word;<br> Shift: TShiftState);<br>var<br> tmpStr:String;<br> ss,ls:integer;<br>begin<br> adoQuery1.Close;<br> adoQuery1.SQL.Clear;<br> adoQuery1.SQL.Add('select ZH from KH_TAB where ZH like "'+Edit1.Text+'%"');<br> adoquery1.Open;<br> if not adoQuery1.Eof then begin<br> tmpStr:=adoQuery1.fieldByName('ZH').AsString ;<br> //label1.Caption:=tmpStr;<br> end<br> else<br> tmpStr:=Edit1.text;<br> ss:=length(Edit1.text);<br> edit1.Text:=tmpStr;<br> ls:=length(tmpStr)-ss;<br> Edit1.SetFocus;<br> Edit1.SelStart:=ss;<br> Edit1.SelLength:=ls;<br><br><br>end;