Главная страница
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.048 c
15-1138286833
Игорь Шевченко
2006-01-26 17:47
2006.02.19
Вот вам и ReactOS :)


2-1138710802
Lenka_per
2006-01-31 15:33
2006.02.19
Переменная в переменной


3-1135261243
Barsky
2005-12-22 17:20
2006.02.19
Значения AutoInc поля только что введенной записи


6-1129584213
Lord_of_Darkness
2005-10-18 01:23
2006.02.19
Рдновременный прием TServerSocket ом файлов от нескольких клиенто


2-1138324137
ПростоТак
2006-01-27 04:08
2006.02.19
Как класс может получить указатель на самого себя ?