Solved

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

Posted on 2004-03-22
3
184 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

729 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