Why am I getting a RichEdit string input error when I call Delete in the OnChange event?

I googled and checked many places to solve, but all the cases that I found were different or included something more advanced than just adding or removing lines. In principle, I want to make a kind of scrollable rich editing (an alternative would be to move the carriage to the bottom, to which I already found a solution).

I add lines to it and check Lines.Countfor an event OnChangefor advanced editing, and as soon as it reaches a value greater than 15, I want to call Lines.Delete(0), however, I get an error:

RichEdit line insertion error

Can someone tell me what I'm doing wrong here?

+3
source share
1 answer

RichEdit line insertion error - , Delphi 2009. , , . , :

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.Clear;
  RichEdit1.Lines.Add('1');
end;

procedure TForm1.RichEdit1Change(Sender: TObject);
begin
  if RichEdit1.Lines.Count > 0 then
    RichEdit1.Lines.Delete(0);
end;

:

1. - TRichEdit.Lines.Add → TRichEdit.Lines.Insert

char , ​​, , ( 0, ) , EM_REPLACESEL, , . , , , OnChange, TRichEdit.Lines.Delete.

2. - TRichEdit.Lines.Delete

- . , , EM_REPLACESEL . , . , TRichEdit.Lines.Insert.

3. - TRichEdit.Lines.Add → TRichEdit.Lines.Insert

, TRichEdit.Lines.Insert, , . , , .

, - , , :

procedure TForm1.Button1Click(Sender: TObject);
begin
  RichEdit1.Lines.Add('1');
end;

procedure TForm1.RichEdit1Change(Sender: TObject);
begin
  RichEdit1.SelStart := 0;
end;

, OnChange , ( , , ).

+4

All Articles