delphi 复制到剪贴板

The Windows Clipboard represents the container for any text or graphics that are cut, copied or pasted from or to an application. This article will show you how to use the TClipboard object to implement cut-copy-paste features in your Delphi application.

Windows剪贴板代表从应用程序剪切,复制或粘贴的任何文本或图形的容器。 本文将向您展示如何使用TClipboard对象在Delphi应用程序中实现剪切复制粘贴功能。

剪贴板一般 ( Clipboard in General )

As you probably know, the Clipboard can hold only one piece of the same kind of data for cut, copy and paste at one time. If we send new information in the same format to the Clipboard, we wipe out what was there before, but the contents of the Clipboard stays with the Clipboard even after we paste those contents into another program.

您可能知道,剪贴板一次只能保存一份相同类型的数据,以便进行剪切,复制和粘贴。 如果我们以相同的格式将新信息发送到剪贴板,则会擦除之前的内容,但是即使将剪贴板中的内容粘贴到另一个程序中,剪贴板中的内容也会保留在剪贴板中。

TC剪贴板 ( TClipboard )

In order to use the Windows Clipboard in our applications, we must add the ClipBrd unit to the uses clause of the project, except when we restrict cutting, copying and pasting to the components already possessing built-in support for Clipboard methods. Those components are TEdit, TMemo, TOLEContainer, TDDEServerItem, TDBEdit, TDBImage and TDBMemo.

为了在我们的应用程序中使用Windows剪贴板,我们必须将ClipBrd单元添加到项目的uses子句中,除非我们将剪切,复制和粘贴限制在已经具有对Clipboard方法的内置支持的组件上。 这些组件是TEdit,TMemo,TOLEContainer,TDDEServerItem,TDBEdit,TDBImage和TDBMemo。

The ClipBrd unit automatically represents a TClipboard object called Clipboard. We'll use the CutToClipboard, CopyToClipboard, PasteFromClipboard, Clear and HasFormat methods to deal with Clipboard operations and text/graphic manipulation.

ClipBrd单元自动表示一个称为剪贴板的TClipboard对象。 我们将使用CutToClipboardCopyToClipboardPasteFromClipboardClearHasFormat方法来处理剪贴板操作和文本/图形操作。

发送和检索文本 ( Send and Retrieve Text )

In order to send some text to the Clipboard the AsText property of the Clipboard object is used. If we want, for example, to send the string information contained in the variable SomeStringData to the Clipboard (wiping out whatever text was there), we'll use the following code:

为了将一些文本发送到剪贴板,使用了剪贴板对象的AsText属性。 例如,如果我们想将变量SomeStringData中包含的字符串信息发送到剪贴板(清除其中的任何文本),我们将使用以下代码:

uses ClipBrd;
...
Clipboard.AsText := SomeStringData_Variable; 

To retrieve the text information from the Clipboard we'll use

要从剪贴板中检索文本信息,我们将使用

uses ClipBrd;
...
SomeStringData_Variable := Clipboard.AsText; 

Note: if we only want to copy the text from, let's say, Edit component to the Clipboard, we do not have to include the ClipBrd unit to the uses clause. The CopyToClipboard method of TEdit copies the selected text in the edit control to the Clipboard in the CF_TEXT format.

注意:如果只想将文本从“编辑”组件复制到剪贴板,则不必在Uses子句中包含ClipBrd单元。 TEdit的CopyToClipboard方法将编辑控件中的选定文本以CF_TEXT格式复制到剪贴板。

procedure TForm1.Button2Click(Sender: TObject) ;
begin//the following line will select    //ALL the text in the edit control    {Edit1.SelectAll;}Edit1.CopyToClipboard;
end; 

剪贴板图像 ( Clipboard Images )

To retrieve graphical images from the Clipboard, Delphi must know what type of image is stored there. Similarly, to transfer images to the clipboard, the application must tell the Clipboard what type of graphics it is sending. Some of the possible values of the Format parameter follow; there are many more Clipboard formats provided by Windows.

要从剪贴板检索图形图像,Delphi必须知道在那里存储了哪种图像。 同样,要将图像传输到剪贴板,应用程序必须告诉剪贴板它正在发送哪种类型的图形。 随后是Format参数的一些可能值; Windows提供了更多剪贴板格式。

  • CF_TEXT - Text with each line ending with a CR-LF combination.

    CF_TEXT-每行以CR-LF组合结尾的文本。

  • CF_BITMAP - A Windows bitmap graphic.

    CF_BITMAP -Windows位图图形。

  • CF_METAFILEPICT - A Windows metafile graphic.

    CF_METAFILEPICT -Windows图元文件图形。

  • CF_PICTURE - An object of type TPicture.

    CF_PICTURE -TPicture类型的对象。

  • CF_OBJECT - Any persistent object.

    CF_OBJECT-任何持久对象。

The HasFormat method returns True if the image in the Clipboard has the right format:

如果剪贴板中的图像格式正确,则HasFormat方法将返回True:

if Clipboard.HasFormat(CF_METAFILEPICT) then ShowMessage('Clipboard has metafile') ; 

Use the Assign method to send (assign) an image to the Clipboard. For example, the following code copies the bitmap from a bitmap object named MyBitmap to the Clipboard:

使用“分配”方法将图像发送(分配)到剪贴板。 例如,以下代码将位图从名为MyBitmap的位图对象复制到剪贴板:

Clipboard.Assign(MyBitmap) ;

In general, MyBitmap is an object of type TGraphics, TBitmap, TMetafile or TPicture.

通常,MyBitmap是TGraphics,T​​Bitmap,TMetafile或TPicture类型的对象。

To retrieve an image from the Clipboard we have to: verify the format of the current contents of the clipboard and use the Assign method of the target object:

要从剪贴板中检索图像,我们必须:验证剪贴板当前内容的格式,并使用目标对象的Assign方法:

{place one button and one image control on form1} {Prior to executing this code press Alt-PrintScreen key combination}
uses clipbrd;
...
procedure TForm1.Button1Click(Sender: TObject) ;
begin
if Clipboard.HasFormat(CF_BITMAP) then Image1.Picture.Bitmap.Assign(Clipboard) ;
end; 

更多剪贴板控制 ( More Clipboard Control )

Clipboard stores information in multiple formats so we can transfer data between applications using different formats. When reading information from the clipboard with Delphi's TClipboard class, we are limited to standard clipboard formats: text, pictures, and metafiles.

剪贴板以多种格式存储信息,因此我们可以使用不同格式在应用程序之间传输数据。 当使用Delphi的TClipboard类从剪贴板中读取信息时,我们仅限于标准剪贴板格式:文本,图片和图元文件。

Suppose you're working between two different Delphi applications; how would you define custom clipboard format in order to send and receive data between those two programs? For the purpose of exploration, let's say you are trying to code a Paste menu item. You want it to be disabled when there is no text in the clipboard (as an instance).

假设您正在两个不同的Delphi应用程序之间工作; 您如何定义自定义剪贴板格式,以便在这两个程序之间发送和接收数据? 出于探索的目的,假设您正在尝试对“粘贴” 菜单项进行编码。 您希望在剪贴板中没有文本(例如)时禁用它。

Since the entire process with the clipboard takes place behind the scenes, there is no method of TClipboard class that will inform you when some change in the content of the clipboard has taken place. The idea is to hook in the clipboard notification system, so you're able to access and respond to events when the clipboard changes.

由于剪贴板的整个过程都在后台进行,因此没有TClipboard类的方法会在剪贴板内容发生某些更改时通知您。 这个想法是挂钩剪贴板通知系统,以便您能够在剪贴板更改时访问并响应事件。

To enjoy more flexibility and functionality, dealing with clipboard change notifications and custom clipboard formats -- listening to the Clipboard -- is necessary.

为了享受更多的灵活性和功能,必须处理剪贴板更改通知和自定义剪贴板格式(侦听剪贴板)。

翻译自: https://www.thoughtco.com/basic-clipboard-operations-cut-copy-paste-1058406

delphi 复制到剪贴板

delphi 复制到剪贴板_Delphi中的基本剪贴板操作(剪切/复制/粘贴)相关推荐

  1. 前端er怎样操作剪切复制以及禁止复制+破解等

    前言 有时候我们经常会碰到这些场景:玩掘金.知乎的时候复制一段文字,总是会在内容后面加上一些版权信息,以及像小说网站等都有禁止选中,禁止复制这种功能,还有点击自动复制账号的功能. 我也经常遇到这些场景 ...

  2. 前端er怎样操作剪切复制以及禁止复制+破解等 1

    前言 有时候我们经常会碰到这些场景:玩掘金.知乎的时候复制一段文字,总是会在内容后面加上一些版权信息,以及像小说网站等都有禁止选中,禁止复制这种功能,还有点击自动复制账号的功能. 我也经常遇到这些场景 ...

  3. delphi 剪切板变量_delphi剪切板-监视剪贴板

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  4. 如何处理SQL Server事务复制中的大事务操作

    如何处理SQL Server事务复制中的大事务操作 事务复制的工作机制 事务复制是由 SQL Server 快照代理.日志读取器代理和分发代理实现的.快照代理准备快照文件(其中包含了已发布表和数据库对 ...

  5. SQL Server中的高可用性(3)----复制 (转载)

    在本系列文章的前两篇对高可用性的意义和单实例下的高可用性做了阐述.但是当随着数据量的增长,以及对RTO和RPO要求的严格,单实例已经无法满足HA/DR方面的要求,因此需要做多实例的高可用性.本文着重对 ...

  6. asp。net中常用的文件操作类

    ** 文件操作类 **/ #region 引用命名空间 using System; using System.Collections.Generic; using System.Text; using ...

  7. DOM中对表格的操作

    DOM中对表格的操作 思考:对表格操作都是对表格哪些东西进行操作? 答:对表格中的属性和方法进行操作 表格中有哪些常用的属性和方法? 下面表格中列出了常用的表操作的属性和方法 下面利用代码演示对表格的 ...

  8. delphi中字符串拼接_Delphi中的字符串类型(Delphi适用于初学者)

    delphi中字符串拼接 As with any programming language, in Delphi, variables are placeholders used to store v ...

  9. java记事本复制粘贴_Java Swing 如何实现记事本中“编辑”菜单下的 剪切,复制,粘贴,删除,全选 功能...

    这篇文字将要学习以下知识点: 1.如何给JButton按钮添加鼠标点击事件监听器 #1.addMouseListener(MouseListener l)  给JButton添加一个鼠标点击监听器l ...

最新文章

  1. [原]Java 正则 多子串 匹配 替换
  2. debian 9系统安装配置iptables
  3. 如何低价坐飞机头等舱
  4. DirectInput:poll轮询理解
  5. tp5 批量更新多条记录_tp5批量导入数据库
  6. diff and colordiff on Ubuntu
  7. foxitreadersdk 打开远程文件_一种最不为人知最简单最方便的用电脑操作手机上的文件...
  8. java 使用三元运算符和if-else获取两个和三个数中的最大值
  9. 腾讯视频手机app下载安装_腾讯视频怎么签到
  10. Gdevops广州站:大咖齐聚,从事运维和数据库的你不能错过!
  11. 4核处理器_买电脑选4核、6核还是8核,从业是十年的专家终于讲清楚了差异
  12. [导入]最近一直在想这个问题
  13. H5 File 对象获取 Input type=file 文件详细信息
  14. nasal脚本起源与环境搭建(flightgear开源项目)
  15. Vs 2017 连接 MySQL
  16. 鼠标自动点击器linux,鼠标自动点击器PC版下载
  17. 使用docker搭建steam 饥荒服务器
  18. C语言小游戏-俄罗斯方块
  19. Windows 11 的“此电脑”图标在哪里?
  20. python中def _init_是什么意思_python3类中的def __init()__如何使用?

热门文章

  1. linux卸载,安装win7碰到的问题总结,使用MbrFix.exe修复mbr
  2. 创业者必须要知道的18条商业定律与法则
  3. Windows查看端口被占用查找步骤
  4. 【使用UltraISO修改镜像】
  5. NOI2002 银河英雄传说
  6. Silverlight.XNA(C#)跨平台3D游戏研发手记:(五)SLG动感增效之《幻影粒子》
  7. Unity将粒子光效导出成png序列帧
  8. carbondata1.5.1编译
  9. 4月28日,邀您参加开鸿智谷教育在鸿OS发行版发布会
  10. RV1126编译及烧写