VCL 中如何使用剪贴板咱就不说了,FMX 做为一个新的框架,提供了跨平台的剪贴板支持。FMX 对剪贴板的支持来自两个接口:
- IFMXClipboardService:位于 FMX.Platform.pas 中1234567891011IFMXClipboardService = 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 中123456789101112131415IFMXExtendedClipboardService=interface(IFMXClipboardService)['{E96E4776-8234-49F9-B15F-301074E23F70}']functionHasText:Boolean;functionGetText:string;procedureSetText(constValue:string);functionHasImage:Boolean;functionGetImage:TBitmapSurface;procedureSetImage(constValue:TBitmapSurface);procedureRegisterCustomFormat(constAFormatName:string);functionIsCustomFormatRegistered(constAFormatName:string):Boolean;procedureUnregisterCustomFormat(constAFormatName:string);functionHasCustomFormat(constAFormatName:string):Boolean;functionGetCustomFormat(constAFormatName:string;constAStream:TStream):Boolean;procedureSetCustomFormat(constAFormatName:string;constAStream:TStream);end;
很明显,第二种更符合VCL中TClipboard的使用习惯。而且如果要使用自定义格式的内容,则必需使用第二种格式,第一种格式的支持情况如下(以10.2 为准,未来版本请自行查看):
- Windows 平台(FMX.Clipboard.Win.pas):文本、位图
- Android 平台(FMX.Clipboard.Android.pas):文本
- iOS 平台(FMX.Clipboard.iOS.pas):文本、位图
- OSX 平台(FMX.Clipboard.Mac.pas):文本、位图
注意一下,支持位图的平台,实际上 TValue 支持的是 TBitmapSurface,当然设置值时也支持 TBitmap ,但 GetClipboard 返回的就只是 TBitmapSurface 类型的对象了。