RichEdit - FindDialog - Scroll-Down - Scroll-Across

Hello All;

   I found the following code that will make the TRichEdit [Scroll-Down] while doing a Search
[ RichEdit.Perform(EM_SCROLL,SB_LINEDOWN,0); ]

But now, I need to find something that will make the TRichEdit [Scroll-Across] while doing a Search?

Any idea's on this one?

Thanks All;

Carrzkiss
LVL 31
Wayne BarronAuthor, Web DeveloperAsked:
Who is Participating?
 
Russell LibbySoftware Engineer, Advisory Commented:
Eg:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    Button1: TButton;
    FindDialog1: TFindDialog;
    procedure FindDialog1Find(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
{$R *.DFM}

procedure TForm1.FindDialog1Find(Sender: TObject);
var  FoundAt:       LongInt;
     StartPos,
     ToEnd:         Integer;
begin
  with RichEdit1 do
  begin
     if SelLength <> 0 then
        StartPos := SelStart + SelLength
    else
        StartPos := 0;
     ToEnd := Length(Text) - StartPos;
     FoundAt := FindText(FindDialog1.FindText, StartPos, ToEnd, []);
     if FoundAt <> -1 then
     begin
        SetFocus;
        SelStart := FoundAt;
        SelLength := Length(FindDialog1.FindText);
        Perform(EM_SCROLLCARET, 0, 0);
     end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
  FindDialog1.Execute;
end;

end.

-- form dfm ---
object Form1: TForm1
  Left = 284
  Top = 114
  Width = 513
  Height = 519
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object RichEdit1: TRichEdit
    Left = 12
    Top = 60
    Width = 421
    Height = 397
    Lines.Strings = (
      'RichEdit1')
    ScrollBars = ssBoth
    TabOrder = 0
    WordWrap = False
  end
  object Button1: TButton
    Left = 12
    Top = 28
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 1
    OnClick = Button1Click
  end
  object FindDialog1: TFindDialog
    Options = [frDown, frFindNext]
    OnFind = FindDialog1Find
    Left = 112
    Top = 24
  end
end

0
 
Russell LibbySoftware Engineer, Advisory Commented:

If the cursor (SelStart) is set to the desired position to be scrolled into view, you can perform the following:

  RichEdit.Perform(EM_SCROLLCARET, 0, 0);

Regards,
Russell
0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
tried that.
This is what I am using:

FindDialog1.Position := Point(RichEdit1.Left + RichEdit1.Width, RichEdit1.Top);
FindDialog1.Execute;
FindDialog1.Perform(EM_SCROLL,SB_LINEDOWN,0);
FindDialog1.Perform(EM_SCROLLCARET,0,0);
RichEdit1.SelStart := RichEdit1.GetTextLen;


I have tried to put the: RichEdit.Perform(EM_SCROLLCARET, 0, 0);
At the bottom line, but still no go.

Can the    ,0,0
Be changed? if so, could you explain what each of them will do?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Russell LibbySoftware Engineer, Advisory Commented:

Why are you having the **dialog** perform the EM_SCROLL and EM_SCROLLCARET messages? The RichEdit needs to perform the messages. And why are you setting the SelStart to the full text text len of the control, vs the text that you are searching for?

Russell
0
 
Wayne BarronAuthor, Web DeveloperAuthor Commented:
That works perfect.
I just have to find out "Why" it is not working in my project?
Very strang, there is nothing different about the the 2-RichEdits.
But your code with scroll to the right,
Mine will not?

Just going to have to do some checking and find out what is going on.

----
As for the code that I supplied that I was using.
That is how I found it.
Should have done some more research on the code before using it.

Thanks Russell. (Added another [125] to the total)
Wayne
0
 
Russell LibbySoftware Engineer, Advisory Commented:
Anytime Wayne, thanks much ;-)

Regards,
Russell
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.