Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Начинающим";
Текущий архив: 2006.02.19;
Скачать: [xml.tar.bz2];

Вниз

Реализация функции 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;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.035 c
6-1131460316
vishnia
2005-11-08 17:31
2006.02.19
Работа ISAPI DLL


2-1138481796
petr
2006-01-28 23:56
2006.02.19
список таблиц


15-1138526367
palva
2006-01-29 12:19
2006.02.19
О выборе и оценке криптоалгоритма


15-1138261865
PMan
2006-01-26 10:51
2006.02.19
Поддержка ПО - стоит браться?


2-1138099753
Змей
2006-01-24 13:49
2006.02.19
регулировка звука(только не баньте тему плз)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский