Removing focus does not stop auto scrolling in a RichEdit control in Delphi 11.3

46 Views Asked by At

I would like to add lines at the end of a RichEdit control which has more lines than can fit into the set height of the control, without these new lines being displayed on the screen.

Here is a test code that demonstrates the issue:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    AddLine: TButton;
    procedure AddLineClick(Sender: TObject);
    procedure RichEdit1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.AddLineClick(Sender: TObject);
var
 i : integer;
begin
 form1.RichEdit1.HideSelection := true;
 form1.RichEdit1.Clear;
 for i := 1 to 100 do
  Form1.RichEdit1.Lines.Add('Add New Line # ' + IntToStr(i));
 end;

procedure TForm1.RichEdit1Change(Sender: TObject);
begin
 form1.AddLine.SetFocus;
end;

end.

The form has a RichEdit control and a button. The height of the RichEdit control can fit 10 lines of text. Pressing the button sets the HideSelection property of the RichEdit control to true and adds 100 lines to the RichEdit control. The onChange event of the RichEdit control sets focus away from the control.

In a previous version of Delphi (2005) this code would prevent auto scrolling when adding lines, however a different behaviour is seen in Delphi 11.3 – the newly added lines are continuously displayed on the screen.

Any suggestions on how to prevent auto scrolling in Delphi 11.3 will be very much appreciated.

Thank you for your help,

Leonid

0

There are 0 best solutions below