VCL 中如何使用剪贴板咱就不说了,FMX 做为一个新的框架,提供了跨平台的剪贴板支持。FMX 对剪贴板的支持来自两个接口:

  • IFMXClipboardService:位于 FMX.Platform.pas 中

     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
      IFMXClipboardService = interface(IInterface)
        ['{CC9F70B3-E5AE-4E01-A6FB-E3FC54F5C54E}']
        /// <summary>
        ///   Gets current clipboard value
        /// </summary>
        function GetClipboard: TValue;
        /// <summary>
        ///   Sets new clipboard value
        /// </summary>
        procedure SetClipboard(Value: TValue);
      end;
  • IFMXExtendedClipboardService:位于 FMX.Clipboard.pas 中
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
      IFMXExtendedClipboardService = interface(IFMXClipboardService)
        ['{E96E4776-8234-49F9-B15F-301074E23F70}']
        function HasText: Boolean;
        function GetText: string;
        procedure SetText(const Value: string);
        function HasImage: Boolean;
        function GetImage: TBitmapSurface;
        procedure SetImage(const Value: TBitmapSurface);
        procedure RegisterCustomFormat(const AFormatName: string);
        function IsCustomFormatRegistered(const AFormatName: string): Boolean;
        procedure UnregisterCustomFormat(const AFormatName: string);
        function HasCustomFormat(const AFormatName: string): Boolean;
        function GetCustomFormat(const AFormatName: string; const AStream: TStream): Boolean;
        procedure SetCustomFormat(const AFormatName: string; const AStream: TStream);
      end;

很明显,第二种更符合VCL中TClipboard的使用习惯。而且如果要使用自定义格式的内容,则必需使用第二种格式,第一种格式的支持情况如下(以10.2 为准,未来版本请自行查看):

  1. Windows 平台(FMX.Clipboard.Win.pas):文本、位图
  2. Android 平台(FMX.Clipboard.Android.pas):文本
  3. iOS 平台(FMX.Clipboard.iOS.pas):文本、位图
  4. OSX 平台(FMX.Clipboard.Mac.pas):文本、位图

注意一下,支持位图的平台,实际上 TValue 支持的是 TBitmapSurface,当然设置值时也支持 TBitmap ,但 GetClipboard 返回的就只是 TBitmapSurface 类型的对象了。

好了,回归正转,说一下基本的使用步骤:

  1. 引用 fmx.platform 单元,如果使用第二个接口,同时使用 fmx.clipboard 单元。
  2. 用  TPlatformServices.Current.SupportsPlatformService 函数来获取剪贴板服务接口实例。
  3. 调用获取的接口实例的相关函数来执行相关的功能。

一个简单的示例:

Delphi/Pascal
 
1
2
3
4
5
6
7
8
9
procedure TForm1.Button1Click(Sender: TObject);
var
  AClipboard:IFMXClipboardService;
begin
  if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService,AClipboard) then
    begin
      AClipboard.SetClipboard('Hello,world from delphi');
    end;
end;

至于其它的几个接口,大家看相关接口的帮助就可以了。

最新文章

  1. java 访问修饰符
  2. IOS UIActivityIndicatorView 等待指示器
  3. mysql update from 子查询
  4. Character Encoding tomcat.
  5. 创建第一个freemarker
  6. Oracle 11g 环境,使用utl_smtp创建一个存储过程来发送邮件
  7. Ubuntu上安装mono
  8. strace命令详解
  9. PyQT5 helloworld教程(转载)
  10. __x__(16)0906第三天__层叠样式表CSS简介
  11. .NET微信开发Charles突破微信授权,获取任意微信网页源代码(含Https)
  12. Windows邮件客户端
  13. delphi7产生条码
  14. 同种类型不同名字的变量在for循环中操作
  15. 迁移桌面程序到MS Store(6)——.NET Portability Analyzer
  16. POJ - 2299 Ultra-QuickSort(归并排序)
  17. Entity Framework之犹豫不决
  18. php之快速入门学习-17(PHP 命名空间)
  19. Vitamio与FFmpeg、LGPL、GPL的关系
  20. python网络编程--线程的方法,线程池

热门文章

  1. python中关于is,=和==的区别
  2. KMP 算法学习
  3. java笔试手写算法面试题大全含答案
  4. 关于 webpack 的研究
  5. leetcode-按奇偶排序数组II
  6. js关闭当前窗口的几种方法
  7. SQL LIKE 运算符
  8. 对AngularJs的简单了解
  9. build protobuf to a static library
  10. Linux源码与编译出的目标文件汇编代码的一致性问题