Solved

Search in TRichEdit working at win 9x but not win 2k and win xp

Posted on 2004-03-22
3
181 Views
Last Modified: 2010-05-18
Hi all,
This excample below copied from Delphi help, the section of  TRichEdit
FindText methods example.

My problem is when searching a text in richedit when the text found, the
cursor must be locate at the position of the text. This example is working
properly under Win9x but not locating at WindowsXP and Windows 2K  and I am
using Delphi 6.


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;

Thanks for answers.


0
Comment
Question by:albay
  • 3
3 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10650529
you may need the scroll_caret-api after you found your text,
sample follows . . .
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 500 total points
ID: 10650572
just add this line

     Perform(EM_SCROLLCARET, 0, 0);

after you set the selsstart-property

the richedit-unit may be added into the uses-clause

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10650584
.....
    FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd,
[stMatchCase]);
    if FoundAt <> -1 then
    begin
      SetFocus;
      SelStart := FoundAt;
      SelLength := Length(FindDialog1.FindText);
      Perform(EM_SCROLLCARET, 0, 0); //<-- here i meant or the line before (doesn't matter)
    end
......

meikl ;-)
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question