自动附加/完成从文本文件到编辑框delphi
发布时间:2020-12-15 10:08:49  所属栏目:大数据  来源:网络整理 
            导读:我正在尝试创建一个编辑框,我希望它能够自动附加输入时输入的文本.文本将从文本文件中附加“建议”. 假设我的建议文件有这些: 玛丽莲·梦露 马龙白兰度 迈克·迈尔斯 当我开始在编辑框中输入“M”时,剩下的将出现突出显示(或不显示): “arilyn门罗” 而当
                
                
                
            | 我正在尝试创建一个编辑框,我希望它能够自动附加输入时输入的文本.文本将从文本文件中附加“建议”. 
  
  假设我的建议文件有这些: 当我开始在编辑框中输入“M”时,剩下的将出现突出显示(或不显示): 解决方法
 您可以使用 
  TComboBox轻松实现此功能.按着这些次序 : 
 const
MaxHistory=200;//max number of items
procedure TForm1.ComboBoxSearchExit(Sender: TObject);
begin
   //check if the text entered exist in the list,if not add to the list
   if (Trim(ComboBoxSearch.Text)<>'') and (ComboBoxSearch.Items.IndexOf(ComboBoxSearch.Text)=-1) then 
   begin
     if ComboBoxSearch.Items.Count=MaxHistory then
     ComboBoxSearch.Items.Delete(ComboBoxSearch.Items.Count-1);
     ComboBoxSearch.Items.Insert(0,ComboBoxSearch.Text);
   end;
end;
 procedure TForm1.FormClose(Sender: TObject); begin ComboBoxSearch.Items.SaveToFile(ExtractFilePath(ParamStr(0))+'History.txt'); end; 
 procedure TForm1.FormCreate(Sender: TObject); var FileHistory : string; begin FileHistory:=ExtractFilePath(ParamStr(0))+'History.txt'; if FileExists(FileHIstory) then ComboBoxSearch.Items.LoadFromFile(FileHistory); end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! | 
