Search code examples
delphidelphi-xe5

How to insert text at caret position in SynEdit


There is a procedure SynEdit.InsertTextAtCaret('Text') for Lazarus version of SynEdit. How to insert text at caret for Delphi version of SynEdit with undo support?


Solution

  • There is procedure

    TCustomSynEdit.procedure InsertBlock(const BB, BE: TBufferCoord; ChangeStr: PWideChar; AddToUndoList: Boolean);
    

    It inserts ChangeStr changing text from BB to BE position. You may set BB and BE to current caret coordinates and you'll get what you want

    For example

    SynEdit1.InsertBlock(SynEdit1.CaretXY, SynEdit1.CaretXY, 'test', true);