unit tc_main;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  Dialogs, ecSyntMemo, ecMacroRec, ecStrUtils;

type
  TForm7 = class(TForm)
    SyntaxMemo1: TSyntaxMemo;
    procedure SyntaxMemo1TextChanged(Sender: TObject; Pos, Count,
      LineChange: Integer);
    procedure SyntaxMemo1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure SyntaxMemo1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form7: TForm7;

implementation

{$R *.dfm}

procedure TForm7.SyntaxMemo1TextChanged(Sender: TObject; Pos, Count,
  LineChange: Integer);
var k: integer;
    p: TPoint;
begin
  with SyntaxMemo1 do
   begin
     p := StrPosToCaretPos(Pos);
     k := System.Pos(#13, Lines.SubString(Pos + 1, Count));
     if k > 0 then Count := k - 1;
     if Count = 0 then Exit;
     if (p.x + Count > 20) then
      begin
        CaretPos := Point(20, p.Y);
        InsertText(sLineBreak);
        CaretStrPos := Pos + Count + Length(sLineBreak);
      end;
   end;
end;

procedure TForm7.SyntaxMemo1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if SyntaxMemo1.CaretPos.X > 20 then
    Key := 0;
end;

procedure TForm7.SyntaxMemo1KeyPress(Sender: TObject; var Key: Char);
begin
  if SyntaxMemo1.CaretPos.X > 20 then
    Key := #0;
end;

end.
