Delphi XE8中的Firemonkey应用程序将文本复制到剪贴板


本文整理自网络,侵删。

 
介绍如何在Delphi XE8中使用Firemonkey应用程序将文本复制到剪贴板。

要使用剪贴板,请使用IFMXClipboardService接口。

检查运行应用程序的平台是否可以使用IFMXClipboardService。

var
  ClipboardService: IFMXClipboardService;

if TPlatformServices.Current.SupportsPlatformService(
  IFMXClipboardService, IInterface(ClipboardService)) then
begin

end;
如果IFMXClipboardService可用,则变量ClipboardService 包含IFMXClipboardService的实例。

要将字符串复制到剪贴板,请使用IFMXClipboardService的SetClipboard方法。

ClipboardService.SetClipboard('文字');
将字符串复制到剪贴板的代码如下:

uses FMX.Platform;

procedure TForm1.Button1Click(Sender: TObject);
var
  ClipboardService: IFMXClipboardService;
begin
  if TPlatformServices.Current.SupportsPlatformService(
    IFMXClipboardService, IInterface(ClipboardService)) then
  begin
    ClipboardService.SetClipboard('文字');
  end;
end;
下面的示例应用程序获取运行该应用程序的平台上可用目录的路径,并将其复制到剪贴板。

在窗体上放置一个按钮组件(TButton)和一个备注组件(TMemo)。


描述表单的OnCreate事件和按钮的OnClick事件。

uses System.IOUtils, FMX.Platform;

procedure TForm1.Button1Click(Sender: TObject);
var
  ClipboardService: IFMXClipboardService;
begin
  Memo1.SelectAll;

  if TPlatformServices.Current.SupportsPlatformService(
    IFMXClipboardService, IInterface(ClipboardService)) then
  begin
    ClipboardService.SetClipboard(Memo1.Text);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Memo1.Lines.Add('System.IOUtils.TPath.GetLibraryPath='+System.IOUtils.TPath.GetLibraryPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetDocumentsPath='+System.IOUtils.TPath.GetDocumentsPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetHomePath='+System.IOUtils.TPath.GetHomePath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedAlarmsPath='+System.IOUtils.TPath.GetSharedAlarmsPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetPublicPath='+System.IOUtils.TPath.GetPublicPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedDocumentsPath='+System.IOUtils.TPath.GetSharedDocumentsPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetDownloadsPath='+System.IOUtils.TPath.GetDownloadsPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetMoviesPath='+System.IOUtils.TPath.GetMoviesPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetMusicPath='+System.IOUtils.TPath.GetMusicPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetPicturesPath='+System.IOUtils.TPath.GetPicturesPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetRingtonesPath='+System.IOUtils.TPath.GetRingtonesPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedDownloadsPath='+System.IOUtils.TPath.GetSharedDownloadsPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedMoviesPath='+System.IOUtils.TPath.GetSharedMoviesPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedMusicPath='+System.IOUtils.TPath.GetSharedMusicPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedCameraPath='+System.IOUtils.TPath.GetSharedCameraPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedPicturesPath='+System.IOUtils.TPath.GetSharedPicturesPath);
  Memo1.Lines.Add('System.IOUtils.TPath.GetSharedRingtonesPath='+System.IOUtils.TPath.GetSharedRingtonesPath);
end;

相关阅读 >>

Delphi 在ie上增添一个按钮

Delphi xe5 android 使用system.zip单元释放资源文件

Delphi 利用hook技术实现键盘监控

Delphi中判断字符串是否为数字

Delphi kbmmw安装

Delphi 实现从下载链接提取文件名的函数

Delphi clientdataset 与fdmemtable 创建 字段与追加记录

Delphi listview的用法

Delphi net.httpclient正则批量获取网页代码中的数值

Delphi xe6 利用fastmm4检测内存泄漏

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...