各位高手,请问用delphi做记事本的时候怎样才能实现查找与替换功能呢?
我是说在主菜单上单击“搜索”——“查找”,就可以跳出一用与实现查找的对话框呢?在哪里可以找到代码呢?

解决方案 »

  1.   

    试试
    FindDialog和ReplaceDialog         FindDialog和ReplaceDialog提供了查找、替换两个对话框部件,对于寻找和替换文本是极其有用的。在FindDialog和ReplaceDialog中都有OnFind事件,当用户单击寻找对话框中的Find Next按钮时将触发这一事件。FindText属性中保存了用户在Find What编辑框中输入的文本。在ReplaceDialog中还有OnReplace事件,当用户单击替换对话框中的Replace和Replace All按钮时,将触发OnReplace事件。FindText和ReplaceText属性分别保存了用户在Find What和Replace With编辑框中输入的文本。 
      

  2.   

    郁闷。。This example requires a TRichEdit, a TButton, and a TFindDialog.
    Clicking the button click will display a Find Dialog to the right of the edit control.  Filling in the "Find what" text and pressing the Find Next button will select the first matching string in the Rich Edit control that follows the previous selection.procedure TForm1.Button1Click(Sender: TObject);begin
      FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
      FindDialog1.Execute;
    end;procedure TForm1.FindDialog1Find(Sender: TObject);
    var
      FoundAt: LongInt;
      StartPos, ToEnd: Integer;
    begin
      with RichEdit1 do
      begin
        { begin the search after the current selection if there is one }
        { otherwise, begin at the start of the text }
        if SelLength <> 0 then      StartPos := SelStart + SelLength;
        else      StartPos := 0;    { ToEnd is the length from StartPos to the end of the text in the rich edit control }    ToEnd := Length(Text) - StartPos;    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, [stMatchCase]);
        if FoundAt <> -1 then
        begin
          SetFocus;
          SelStart := FoundAt;
          SelLength := Length(FindDialog1.FindText);
        end;
      end;
    end;
      

  3.   

    FindDialog和ReplaceDialog的属性怎么设置呢?
    运行的代码又 是什么呢?
      

  4.   

    替换:
     procedure TFrom1.replacedialog1replace(sender:Tobject);
     var found:longint;
       spos,epos:Integer;
       B:PChar;
    begin
    with richedit1 do 
    begin
    if SelLength<>0 then
       begin
       spos:=SelStart+SelLength;
       end else begin
       SPos:=0;
       end;
    EPos:=Length(Text)-SPos;
    Found:=FindText(Replacedialog1.findtext,spos,epos,[stMatchCase]);
    if found<>-1 then
       begin
       SetFocus;
       SelStart:=Found;
       SelLength:=Length(ReplaceDialog1.FindText);
       B:=PChar(Length(RePlaceDialog1.FindText));
       RichEidt1.SetselTextBuf(B); 
       end;
    end;
    end;
    end
    查找:同上了
      把后面的几个语句去掉。
    B:=PChar(Length(RePlaceDialog1.FindText));
       RichEidt1.SetselTextBuf(B);