Тема: findialog memo
Показать сообщение отдельно

  #3  
Старый 25.03.2009, 17:51
slesh
Познавший АНТИЧАТ
Регистрация: 05.03.2007
Сообщений: 1,985
С нами: 10097606

Репутация: 3349


По умолчанию

стандартный пример из Delphi World + парочку строк отсебятины
Код:
var
 FSelPos: integer;


procedure TForm1.Button1Click(Sender: TObject);
begin
 FindDialog1.Execute;
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
 S:string;
 startpos:integer;
 line:integer;
 x:integer;
begin
 with TFindDialog(Sender) do
  begin
   if FSelPos=0 then Options:=Options-[frFindNext];
   if frfindNext in Options then
    begin
     StartPos:=FSelPos+Length(Findtext);
     S:=Copy(Memo1.Lines.Text, StartPos, MaxInt);
    end
   else
    begin
     S:=Memo1.Lines.Text;
     StartPos:=1;
    end;
   FSelPos:=Pos(FindText, S);
   if FSelPos>0 then
    begin
     FSelPos:=FSelPos+StartPos-1;
     s:=memo1.Lines.Text;
     line:=1;
     for x:=1 to FSelPos-1 do if (s[x]=#13) and (s[x+1]=#10) then inc(line);
     label1.Caption:=inttostr(line)+': '+memo1.lines.Strings[line-1];
     Memo1.SelStart:=FSelPos-1;
     Memo1.SelLength:=Length(FindText);
     Memo1.SetFocus;
    end
   else
    begin
     if frfindNext in Options then S:=Concat('There are no further occurences of "', FindText,'" in Memo1.')
       else S:=Concat('Could not find "', FindText, '" in Memo1.');
     MessageDlg(S, mtError, [mbOK], 0);
    end;
  end;
end;

Последний раз редактировалось slesh; 25.03.2009 в 17:53..
 
Ответить с цитированием