[How to] How to switch Insert/Overtype mode

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17254
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[How to] How to switch Insert/Overtype mode

Post by Sergey Tkachenko »

The overwrite mode is not supported directly, but you can implement it using events.
The code is below.

Code: Select all

var IgnoreNextChar: Boolean = False;

procedure TForm1.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  IgnoreNextChar := RichViewEdit1.SelectionExists;
end;

procedure TForm1.RichViewEdit1KeyPress(Sender: TObject; var Key: Char);
var rve: TCustomRichViewEdit;
    ItemNo, Offs: Integer;
begin
  if IgnoreNextChar then begin
    IgnoreNextChar := False;
    exit;
  end;
  IgnoreNextChar := False;
  if not ((Key=#9) or (Key>=' ')) then
    exit;
  rve := RichViewEdit1.TopLevelEditor;
  if rve.SelectionExists then
    exit;
  ItemNo := rve.CurItemNo;
  Offs  := rve.OffsetInCurItem;
  if (Offs>=rve.GetOffsAfterItem(ItemNo)) then begin
    if (ItemNo+1<rve.ItemCount) and
       not rve.IsFromNewLine(ItemNo+1) then begin
      inc(ItemNo);
      Offs := rve.GetOffsBeforeItem(ItemNo);
      end
    else
      exit;
  end;
  rve.SetSelectionBounds(ItemNo, Offs, ItemNo, Offs+1);
  rve.Invalidate;
end;
Sergey Tkachenko
Site Admin
Posts: 17254
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Demo: http://www.trichview.com/support/files/ins.zip

Includes this code + switching modes when user pressed the Insert key.
Post Reply