结果:
发现个问题,就是粘贴时会清除之前的信息。
1 unit Unit1; 2 3 interface 4 5 uses 6 System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants, 7 FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, 8 System.Rtti,//需要引入 9 FMX.platform, FMX.ScrollBox, FMX.Memo, FMX.Edit, FMX.Controls.Presentation, 10 FMX.StdCtrls;//需要引入 11 12 type 13 TForm1 = class(TForm) 14 Button1: TButton; 15 Button2: TButton; 16 Edit1: TEdit; 17 Memo1: TMemo; 18 Button3: TButton; 19 Button4: TButton; 20 Memo2: TMemo; 21 Button5: TButton; 22 procedure FormCreate(Sender: TObject); 23 procedure Button1Click(Sender: TObject); 24 procedure Button2Click(Sender: TObject); 25 procedure Button5Click(Sender: TObject); 26 procedure Button3Click(Sender: TObject); 27 procedure Button4Click(Sender: TObject); 28 private 29 { Private declarations } 30 public 31 { Public declarations } 32 //定义剪切板全局变量化 33 FClipboardService: IFMXClipboardService; 34 end; 35 36 var 37 Form1: TForm1; 38 39 implementation 40 {$R *.fmx} 41 {$R *.NmXhdpiPh.fmx ANDROID} 42 43 procedure TForm1.Button1Click(Sender: TObject); 44 begin 45 //法一,用控件自带的方法实现拷贝 46 Edit1.SelectAll; 47 Edit1.CopyToClipboard; 48 end; 49 50 procedure TForm1.Button2Click(Sender: TObject); 51 begin 52 //法一,用控件自带的方法实现拷贝 53 Memo1.SelectAll; 54 Memo1.CopyToClipboard; 55 end; 56 57 procedure TForm1.Button3Click(Sender: TObject); 58 begin 59 //法二,用系统的剪切板来实现拷贝 60 FClipboardService.SetClipboard(Tvalue(Edit1.Text)); 61 end; 62 63 procedure TForm1.Button4Click(Sender: TObject); 64 begin 65 //法二,用系统的剪切板来实现拷贝 66 FClipboardService.SetClipboard(Tvalue(Memo1.Text)); 67 end; 68 69 procedure TForm1.Button5Click(Sender: TObject); 70 begin 71 //从系统剪切板得到数据实现粘贴 72 Memo2.Text := FClipboardService.GetClipboard.ToString; 73 end; 74 75 procedure TForm1.FormCreate(Sender: TObject); 76 begin 77 //初始化剪切板 78 TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, IInterface(FClipboardService)); 79 end; 80 81 end.
时间: 2024-10-10 09:33:59