首页 技术 正文
技术 2022年11月14日
0 收藏 436 点赞 4,999 浏览 2093 个字

[FMX]在你的跨平台应用中使用剪贴板进行复制粘贴

2017-08-10 • AndroidC++ BuilderDelphiiOS教程 • 暂无评论 • swish •浏览 516 次

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

  • IFMXClipboardService:位于 FMX.Platform.pas 中

     

    1234567891011   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 中 
    123456789101112131415   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. 调用获取的接口实例的相关函数来执行相关的功能。

一个简单的示例:

 

123456789 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;

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

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,406
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898