⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ufindinfile.pas

📁 delphi 写的delphi的程序 Handel is a free, standalone development tool created with Delphi 3 that enable
💻 PAS
字号:
unit UFindInFile;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TFindInFile = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    cbSearch: TComboBox;
    GroupBox1: TGroupBox;
    chkMatchCase: TCheckBox;
    chkWholeWord: TCheckBox;
    btnOK: TButton;
    btnCancel: TButton;
    ListView1: TListView;
    Animate1: TAnimate;
    procedure FormActivate(Sender: TObject);
    procedure cbSearchKeyPress(Sender: TObject; var Key: Char);
    procedure btnOKClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ListView1DblClick(Sender: TObject);
  private
    { Private declarations }
    MatchingPos: Integer;
    procedure LoadFindStr;
    function  SearchingText(SearchStr:string;Options:TSearchTypes):Boolean;
  public
    { Public declarations }
  end;

var
  FindInFile: TFindInFile;

implementation

uses  utils,uconst,MAINFORM, Editor, mwCustomEdit;

{$R *.DFM}

procedure TFindInFile.FormActivate(Sender: TObject);
begin
   MatchingPos:=0;
   cbSearch.SetFocus;
end;

procedure TFindInFile.cbSearchKeyPress(Sender: TObject; var Key: Char);
begin
   if Key = #13 then  begin
      ModalResult:= mrOK;
      btnOKClick(self);
      Key:= #0;
   end;
end;

procedure TFindInFile.btnOKClick(Sender: TObject);
var
  Options: TSearchTypes;
begin
   SaveFindText(cbSearch.Text);
   Height:= 310;
   ListView1.Items.Clear;
   Animate1.Active:= True;
   ListView1.Visible:= True;
   if (chkWholeWord.Checked) then Include(Options,stWholeWord);
   if (chkMatchCase.Checked) then Include(SearchOption, mwsoMatchCase);
   SearchingText(cbSearch.Text,Options);
   Animate1.Active:= False;
end;

// 傈俊 八祸茄 巩磊凯阑 霓焊 冠胶俊 眠啊茄促.
procedure TFindInFile.LoadFindStr;
var
   I,Pos1:integer;
   TextList: TStringList;
begin
    TextList := TStringList.Create;
    IniFile.ReadSectionValues('FindText',TextList);
    if TextList.Count<1 then Exit;
    cbSearch.Items.Clear;
    for I:=TextList.Count-1 downto 1 do begin
        Pos1:=Pos('=',TextList[I]);
        if Pos1>0 then
           cbSearch.Items.Add(Copy(TextList[I],Pos1+1,Length(TextList[I])));
    end;
    TextList.Free;
end;

procedure TFindInFile.FormCreate(Sender: TObject);
begin
   Height:= 200;
   LoadFindStr;
end;

// 巩磊凯阑 八祸茄促.
function TFindInFile.SearchingText(SearchStr:string;Options:TSearchTypes):Boolean;
var
   FindOption:TSearchTypes;
   I,StartPos,LinePos,TempPos:integer;
   RichEdit:TRichEdit;
   NewItem: TListItem;
   Text: array[0..4095] of Char;
   L: Integer;
   S:String;
begin
    Result:= True;
    with EditorForm.PageControl1 do begin
       for I:=0 to PageCount-1 do begin
          RichEdit:= TRichEdit(Pages[I].Controls[0]);
          MatchingPos:=0;
          while MatchingPos <> -1 do begin
          MatchingPos:=RichEdit.FindText(SearchStr,MatchingPos,RichEdit.GetTextlen,Options);
          if MatchingPos<>-1 then begin // 巩磊凯 八祸俊 己傍茄 版快
             NewItem:= ListView1.Items.Add;
             NewItem.Caption:= Pages[I].Caption;
             NewItem.SubItems.Add(IntToStr(MatchingPos));
             // 茫篮 巩磊凯捞 乐绰 青狼 郴侩阑 焊咯霖促.
             LinePos:=SendMessage(RichEdit.Handle, EM_LINEFROMCHAR, MatchingPos,0);
             L := SendMessage(RichEdit.Handle, EM_GETLINE, LinePos, Longint(@Text));
             if (Text[L - 2] = #13) and (Text[L - 1] = #10) then Dec(L, 2);
             SetString(S, Text, L);
             NewItem.SubItems.Add(S);
             Inc(MatchingPos);
          end;
          end;
       end;
    end;
end;

procedure TFindInFile.ListView1DblClick(Sender: TObject);
var
  I:Integer;
  RichEdit: TRichEdit;
begin
    with EditorForm.PageControl1 do begin
       for I:=0 to PageCount-1 do begin
         if Pages[I].Caption = ListView1.Selected.Caption then begin
            ActivePage:= Pages[I];
            Pages[I].SetFocus;
            RichEdit:= TRichEdit(Pages[I].Controls[0]);
            RichEdit.SelStart:= StrToInt(ListView1.Selected.SubItems[0]);
            RichEdit.SelLength:= Length(cbSearch.Text);
         end;
       end;
    end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -