Solved

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

Posted on 2004-03-22
3
183 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…

726 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