Android实例-如何使用系统剪切板(XE8+小米2)

Android实例-如何使用系统剪切板(XE8+小米2)

结果:

发现个问题,就是粘贴时会清除之前的信息。

 unit Unit1;

 interface

 uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
System.Rtti,//需要引入
FMX.platform, FMX.ScrollBox, FMX.Memo, FMX.Edit, FMX.Controls.Presentation,
FMX.StdCtrls;//需要引入 type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button3: TButton;
Button4: TButton;
Memo2: TMemo;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//定义剪切板全局变量化
FClipboardService: IFMXClipboardService;
end; var
Form1: TForm1; implementation
{$R *.fmx}
{$R *.NmXhdpiPh.fmx ANDROID} procedure TForm1.Button1Click(Sender: TObject);
begin
//法一,用控件自带的方法实现拷贝
Edit1.SelectAll;
Edit1.CopyToClipboard;
end; procedure TForm1.Button2Click(Sender: TObject);
begin
//法一,用控件自带的方法实现拷贝
Memo1.SelectAll;
Memo1.CopyToClipboard;
end; procedure TForm1.Button3Click(Sender: TObject);
begin
//法二,用系统的剪切板来实现拷贝
FClipboardService.SetClipboard(Tvalue(Edit1.Text));
end; procedure TForm1.Button4Click(Sender: TObject);
begin
//法二,用系统的剪切板来实现拷贝
FClipboardService.SetClipboard(Tvalue(Memo1.Text));
end; procedure TForm1.Button5Click(Sender: TObject);
begin
//从系统剪切板得到数据实现粘贴
Memo2.Text := FClipboardService.GetClipboard.ToString;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
//初始化剪切板
TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, IInterface(FClipboardService));
end; end.
上一篇:Java技术学习路线笔记:Maven安装和作用


下一篇:linux使用FIO测试磁盘的iops