Главная страница
    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.45 MB
Время: 0.053 c
2-1138520899
acer
2006-01-29 10:48
2006.02.19
данные в treenode


2-1139124884
wany
2006-02-05 10:34
2006.02.19
отбор данных за период


2-1138881592
Starter2006
2006-02-02 14:59
2006.02.19
Delphi + 1C


2-1138370764
Glex
2006-01-27 17:06
2006.02.19
Помогите решить задачу. Проблема чисто техническая.


2-1138774760
dabreezy
2006-02-01 09:19
2006.02.19
Вопрос по TabControl





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
Английский Французский Немецкий Итальянский Португальский Русский Испанский