Cutting, Copying, and Pasting Text

From RAD Studio
Jump to: navigation, search

Go Up to Working with Text in Controls

Applications that use the Clipbrd unit can cut, copy, and paste text, graphics, and objects through the clipboard. The edit components that encapsulate the standard text-handling controls all have methods built into them for interacting with the clipboard.

To cut, copy, or paste text with the clipboard, call the edit component's CutToClipboard, CopyToClipboard, and PasteFromClipboard methods, respectively.

For example, the following code attaches event handlers to the OnClick events of the Edit > Cut, Edit > Copy, and Edit > Paste commands, respectively:

 procedure TEditForm.CutToClipboard(Sender: TObject);
 begin
   Editor.CutToClipboard;
 end;
 procedure TEditForm.CopyToClipboard(Sender: TObject);
 begin
   Editor.CopyToClipboard;
 end;
 procedure TEditForm.PasteFromClipboard(Sender: TObject);
 begin
   Editor.PasteFromClipboard;
 end;
void __fastcall TMainForm::EditCutClick(TObject* Sender) {
	RichEdit1->CutToClipboard();
}

void __fastcall TMainForm::EditCopyClick(TObject* Sender) {
	RichEdit1->CopyToClipboard();
}

void __fastcall TMainForm::EditPasteClick(TObject* Sender) {
	RichEdit1->PasteFromClipboard();
}


See Also

Code Examples