by Erick Engelke
Written Feb 9, 2026
It’s possible to use Ctrl/Command C and Ctrl/Command V to cut and paste text into a multiline edit. But how can you programmatically force a cut and paste.
There are two steps to this process:
-
accessing the clipboard
-
inserting text into the MultiLineEdit (or in fact any editor)
Accessing the Clipboard
This step is harder than you might think. Ignore EWB’s IDE, it’s InternetExplorer based and is outdated.
Modern browsers only support the clipboard when you have certain circumstances:
-
SSL certificate
-
or localhost based server (for testing)
So if this example isn’t working, check that you meet these criteria.
Also EWB definitions don’t include the modern clipboard object, so you need to define TNav2 which is an extended navigator class, and cast it onto window.navigator.
Look at the pasteclipboard() function below to see how you can access the clipboard and call inserttext() with a string.
Inserting Text into a MultiLineEdit
You want to push the text into the current cursor location. If some text is highlighted, you want to replace it.
We use trusty SelectionStart and SelectionEnd to find these two points (often they are identical), and insert the text between them.
See InsertText() to see how that’s done.
I’ve defined a TButton which calls btPasteClick in its onclick handler.
That’s all.
unit pasteunit;
interface
uses WebCore, WebUI, WebForms, WebCtrls, WebEdits, WebBtns, webdom;
type
TForm1 = class(TForm)
MultiLineEdit1: TMultiLineEdit;
btPaste: TButton;
procedure btPasteClick(Sender: TObject);
private
{ Private declarations }
procedure PasteClipboard;
procedure InsertTExt( s : string );
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
TClipFunction = procedure( x : string );
external TClipboardThen = class (TExternalObject )
public
procedure then( fn : TClipFunction );
end;
external TCLipboard = class( TExternalObject )
public
function readText : TClipboardThen;
procedure writeText( s : string );
end;
external TNav2 = class( TNavigator )
public
property clipboard : TClipboard read ;
end;
procedure TForm1.PasteClipboard;
begin
TNav2(window.navigator).clipboard.readText().then( inserttext );
end;
type
external TEvent2 = class( TEvent )
public
property clipboardData : TClip2 read;
end;
external TClip2 = class( TExternaloBJECT )
public
function getData(s:string) : string;
end;
TMultilinedit2 = class( TMultilineedit )
public
prototype : variant;
end;
var
external globalinput : THTMLElement;
procedure TForm1.InsertText( s : string );
var
start,last : integer;
old : string;
begin
multilineedit1.setfocus;
start := multilineedit1.SelectionStart;
last := multilineedit1.SelectionEnd;
multilineedit1.Lines.Text := copy( multilineedit1.Lines.Text, 1, start ) + s + copy( multilineedit1.Lines.Text, last+1 );
multilineedit1.SelectionStart := start + length( s ) ;
MultiLineedit1.SelectionEnd := multilineEdit1.SelectionStart;
end;
procedure TForm1.btPasteClick(Sender: TObject);
begin
if ( isie ) then
inserttext('...cannot insert text in IE, it cannot access the clipboard...')
else
pasteclipboard;
end;
end.