Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2006.02.19;
Скачать: CL | DM;

Вниз

Реализация функции Find для TRichEdit   Найти похожие ветки 

 
Dormidont ©   (2006-01-31 01:46) [0]

Есть реализация функции Find (см. ниже. честно говоря, не моя, нашел в Инете)
Мои проблемы состоят в том, что:
1.При поиске по тексту, не происходит прокрутки экрана к местоположению карета.
2.Если посли активации окна поиска поменять местоположение курсора, то поиск начинается, не с нового местоположения, а с того которое было до изменения положения.
Бился, бился, по-моему все правильно, должно работать, но нет не работает. Если кому не жалко может глянет, что тут не правильно
или хотя бы намекните, где искать:
procedure TMainForm.OnFind(Sender: TObject);
var
  S : string;
  startpos : integer;
begin
  with TFindDialog(Sender) do
  begin
    {If the stored position is 0 this cannot be a find next. }
    if FSelPos = 0 then
      Options := Options - [frFindNext];

     { Figure out where to start the search and get the corresponding
      text from the memo. }
    if frfindNext in Options then
    begin
      { This is a find next, start after the end of the last found word. }
      StartPos := FSelPos + Length(Findtext);
      S := Copy(Editor.Lines.Text, StartPos, MaxInt);
    end
    else
    begin
      { This is a find first, start at the, well, start. }
      S := Editor.Lines.Text;
      StartPos := 1;
    end;
    { Perform a global case-sensitive search for FindText in S }
    FSelPos := Pos(FindText, S);
    if FSelPos > 0 then
    begin
       { Found something, correct position for the location of the start
        of search. }
      FSelPos := FSelPos + StartPos - 1;
      Editor.SelStart := FSelPos - 1;
      Editor.SelLength := Length(FindText);
      Editor.SetFocus;
    end
    else
    begin
      { No joy, show a message. }
      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;

procedure TMainForm.Find1Click(Sender: TObject);
begin
  FSelPos := 0;
  FindDialog1.Execute;
end;


 
Юрий Зотов ©   (2006-01-31 04:40) [1]

Из справки.

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;



Страницы: 1 вся ветка

Текущий архив: 2006.02.19;
Скачать: CL | DM;

Наверх




Память: 0.47 MB
Время: 0.087 c
2-1138937257
Приятель
2006-02-03 06:27
2006.02.19
Как выровнять record на 149


15-1138686123
Барлог(с)
2006-01-31 08:42
2006.02.19
PS/2 -> COM


2-1138883438
Daria
2006-02-02 15:30
2006.02.19
проблемы с null


15-1138713626
ПЛОВ
2006-01-31 16:20
2006.02.19
Возник такой вопрос интересный


6-1131019628
S46E
2005-11-03 15:07
2006.02.19
Сканирование открытых UDP портов