Solved

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

Posted on 2004-03-22
3
179 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
Comment Utility
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
Comment Utility
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
Comment Utility
.....
    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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi TcxGrid group footer summary 3 143
Virtuailstring tree compare node issue 14 89
Help on project with Soap 10 42
Working with hours 3 31
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now