delphi XE8中的Firemonkey应用程序将文本复制到剪贴板  
官方Delphi 学习QQ群: 682628230(三千人)
频道

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;

推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.040661811828613 seconds