Link to home
Start Free TrialLog in
Avatar of urif
urif

asked on

find dialog onfind event

hi everyone, i've a find dialog and a richedit, below is the code for onfind, this code find the text, marks the text but it doesn;t scroll the richedit, if the found text is out of view (need to scroll to reach) then this code won't do it.

any ideas why? (ActiveRich us a trichedit) thx!

procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: longint;
  SearchType: TSearchTypes;
  SearchStart: integer;
begin
    finddialog1.CloseDialog;

with ActiveRich do
  begin

  if frWholeWord in FindDialog1.Options then
    SearchType:=[stWholeWord]
  else
    SearchType:=[];

  if SelLength > 0 then
    SearchStart:=SelStart + SelLength//1
  else
    SearchStart:=SelStart;

  Screen.Cursor:=crHourGlass;
  Application.ProcessMessages;
  FoundAt:=FindText(FindDialog1.FindText, SearchStart,  
                Length(Text)-SearchStart,
                              SearchType);

  Screen.Cursor:=crDefault;
  Application.ProcessMessages;
  if FoundAt < 1 then
    MessageDlg('Unable to find "'+ FindDialog1.FindText +
               '"', mtInformation, [mbOK], 0)
  else
    begin
    SetFocus;
    SelStart:=FoundAt;
    SelLength:=Length(FindDialog1.FindText);

    end;
  end;
end;
ASKER CERTIFIED SOLUTION
Avatar of Motaz
Motaz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of urif
urif

ASKER

this is the 1st thing i did, still...
But it works here,
did you changed any thing else
I added a new RichEdit, Turing HideSelection to false, and ScroolBar to Both
Avatar of urif

ASKER

nope, the only thing is that i am creating the richedit at run time, but nothing else
I used this code and it works fine:

begin
  if not Assigned(RichEdit1) then
  begin
    RichEdit1:= TRichEdit.Create(nil);
    RichEdit1.Parent:= Self;
    RichEdit1.HideSelection:= False;
  end;
  FindDialog1.Execute;
end;

Motaz
Avatar of urif

ASKER

ok, thanks, there must be something weird going on then...

but thanks for the help