[教学] Delphi IDE 文件搜寻功能

Delphi IDE 提供了一个方便的文件搜寻功能,操作如下:

点 Search 选单内的 Find in Files...

 

例如我们想搜寻 JFile 需要引用那一个源码,可输入如下:

  • 输入关键字:JFile = (加上等号,主要是缩小搜寻范围)
  • 搜寻目录请输入目前 Delphi 版本的源码目录(如:C:\Program Files (x86)\Embarcadero\Studio\18.0\source)

 

按 Ok 开始搜寻,只找到一个文件包含 "JFile =",点二下可以开启:

 

转载于:https://www.cnblogs.com/onechen/p/6485045.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搜索TXT 文件的示例unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ExtCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Memo2: TMemo; Panel1: TPanel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit1: TEdit; ButtonSearchFile: TButton; FolderPath: TEdit; FileExt: TEdit; ProgressBar1: TProgressBar; procedure ButtonSearchFileClick(Sender: TObject); procedure ListBox1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } procedure SearchFile1(FileName: string; FindText: string); function MakeFileList(Path, FileExt: string): TStringList; function FileInUsed(FileName: TFileName): Boolean; public { Public declarations } end; var Form1: TForm1; implementation uses StrUtils; {$R *.dfm} { Search Options KeyWord in file FileName FileSize FileCreateTime FileModifyTime keyword filepath openfile found addListbox } var FileNamePathList, FileNameList: TStringList; procedure TForm1.FormCreate(Sender: TObject); begin FileNameList := TStringList.Create; FileNamePathList := TStringList.Create; end; { if FileInUsed ('D:\Administrator\Documents\MyProjects\FileSearch\Win32\Debug\Project1.exe') then ShowMessage('File is in use.') else ShowMessage('File not in use.'); } function TForm1.FileInUsed(FileName: TFileName): Boolean; var HFileRes: HFILE; begin Result := False; if not FileExists(FileName) then Exit; // 如果文件不存在,返回false HFileRes := CreateFile(PChar(FileName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); Result := (HFileRes = INVALID_HANDLE_VALUE); if not Result then CloseHandle(HFileRes); end; procedure TForm1.SearchFile1(FileName: string; FindText: string); var SearchList: TStringList; begin try SearchList := TStringList.Create; if FileExists(FileName) and (not FileInUsed(FileName)) then begin SearchList.LoadFromFile(FileName); if Boolean(Pos(UpperCase(FindText), UpperCase(SearchList.Text))) then begin FileNameList.Add(ExtractFileName(FileName)); FileNamePathList.Add(FileName); end; end; finally SearchList.Free; end; end; procedure TForm1.ButtonSearchFileClick(Sender: TObject); var I, n: Integer; List: TStringList; begin try ButtonSearchFile.Caption := 'SearchFile'; List := TStringList.Create; List.Clear; FileNameList.Clear; FileNamePathList.Clear; List := MakeFileList(FolderPath.Text, FileExt.Text); ProgressBar1.Max := List.Count; for I := 0 to List.Count - 1 do begin Application.ProcessMessages; SearchFile1(List[I], Edit1.Text); ProgressBar1.Position := I; end; ListBox1.Items.Text := FileNameList.Text; ButtonSearchFile.Caption := IntToStr(FileNamePathList.Count) + ' 条'; finally List.Free; end; end; { 这个过程得显示进度 } function TForm1.MakeFileList(Path, FileExt: string): TStringList; var sch: TSearchrec; begin Result := TStringList.Create; if RightStr(Trim(Path), 1) '\' then Path := Trim(Path) + '\' else Path := Trim(Path); if not DirectoryExists(Path) then begin Result.Clear; Exit; end; if FindFirst(Path + '*', faAnyfile, sch) = 0 then begin repeat Application.ProcessMessages; if ((sch.Name = '.') or (sch.Name = '..')) then Continue; if DirectoryExists(Path + sch.Name) then begin Result.AddStrings(MakeFileList(Path + sch.Name, FileExt)); end else begin if (UpperCase(ExtractFileExt(Path + sch.Name)) = UpperCase(FileExt)) or (FileExt = '.*') then Result.Add(Path + sch.Name); end; until FindNext(sch) 0; FindClose(sch); end; end; procedure TForm1.ListBox1Click(Sender: TObject); var s: string; txt: string; begin if not FileExists(FileNamePathList[ListBox1.ItemIndex]) then Exit; Memo2.Lines.LoadFromFile(FileNamePathList[ListBox1.ItemIndex]); Caption := FileNamePathList[ListBox1.ItemIndex]; txt := Form1.Memo2.Text; if Boolean(Pos(UpperCase(Edit1.Text), UpperCase(txt))) then begin Memo2.SetFocus; Memo2.SelStart := Pos(UpperCase(Edit1.Text), UpperCase(txt)) - 1; Memo2.SelLength := Length(Edit1.Text); end; end; end.
2003.11.26 V0.6.7 + [多语言版] 新增多语言支持,现支持简体、繁体中文及英文。 # [IDE 扩展] 新增 Object Inspector 扩展专家,实现非默认值属性粗体显示功能(暂时只支持 D5/BCB5)。 + [MSDN 专家] 增加对 MSDN.NET 的支持及新增工具栏。 + [辅助功能] 增加专家引导工具,可以在启动 IDE 时按下左 Shift 键来启动该工具,用于临时禁用/启动专家。 * [辅助功能] 增加带帮助的窗体用 F1 调出帮助的功能。 * [删除注释专家] 增加处理项目源文件的选项。 * [工程扩展专家] 修正窗体列表及单元列表导致编辑器失去光标的问题,以及其它的改进。 * [属性编辑器] 修正字符串属性编辑器全部替换可能死循环的错误及部分功能改进。 * [IDE 扩展] 修正按 F12 显示窗体时焦点在浮动面板上的问题。 * [IDE 扩展] 修正浮动面板导致 IDE 中其它窗体 Stay On Top 无效的问题。 * [IDE 扩展] 修正 Close All 可能导致异常的问题。 * [IDE 扩展] 修正当浮动工具条显示时 IDE Edit 中大部分菜单不可使用问题。 * [IDE 扩展] 修正组件面板扩展导致面板不接受鼠标滚轮事件的错误。 * [代码编辑器专家] 修正多个 IDE 同时退出时提示保存冲突的问题。 * [代码编辑器专家] 修正加入过程头时,对 Class methods 处理错误的问题。 * [源代码统计专家] 修正清空统计结果不完全的小错误。 * [属性修改器] 修正由于删除已经修改的控件,引起双击定位到该控件时触发异常的错误。 * [窗体设计专家] 修正不可视组件排列有时不能过滤掉 TField 等不可见组件的问题。 * [辅助功能] 修正部分对话框不能用 ESC 关闭的问题。 * [其它] 修正其它一些已发现的错误及部分专家的功能改进。 ^ [开发计划] 另有资源管理专家、代码编辑器扩展、Explorer 专家、收藏夹专家、MMC 框架向导、DUnit 框架向导等正在开发中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值