FabDev 8 Posted June 30, 2023 (edited) Hello, With this code you can detect if Clipboard contains Text or a bitmap : if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, Svc) then begin Value := Svc.GetClipboard; if not Value.IsEmpty then begin if Value.IsType<string> then begin ATexteSource := Value.ToString; PasteImage.Bitmap := nil; end else if Value.IsType<TBitmapSurface> then begin But how to detect if clipboard contains file ? Because in this case (= after copying files from Windows Explorer) Value.IsEmpty=true Of course the question is for any platform (Windows, IOS, MacOs etc...). Must we use a specific code for each OS ? I know how to do with VCL but not with FMX. Edited June 30, 2023 by FabDev Share this post Link to post
Remy Lebeau 1398 Posted June 30, 2023 (edited) 1 hour ago, FabDev said: With this code you can detect if Clipboard contains Text or a bitmap : ... But how to detect if clipboard contains file ? Unfortunately, you will not be able to do that with FMX's native interfaces, at least on Windows (I didn't look at other platforms). You will have to resort to using the Win32 API directly. On Windows, FMX's default IFMXClipboardService implementation natively supports only the CF_UNICODETEXT and CF_DIB standard clipboard formats. For other clipboard formats, FMX does offer IFMXExtendedClipboardService. However, it only supports clipboard formats that are registered at runtime via its RegisterCustomFormat() method, which on Windows is based on the Win32 RegisterClipboardFormat() API. But files are stored on the Windows clipboard using pre-defined Shell clipboard formats that are not registered at runtime (ie, CF_HDROP, CF_FILENAME, CFSTR_FILEDESCRIPTOR+CFSTR_FILECONTENTS, CFSTR_SHELLIDLIST, etc), so they cannot be accessed with IFMXExtendedClipboardService at this time. I have just now opened a QualityPortal ticket to request that feature be added in a future Delphi release: RSP-41923: Allow IFMXExtendedClipboardService to access custom formats by ID, not just by name Quote Must we use a specific code for each OS ? For Windows, definitely yes. For other platforms, it depends on how their system clipboards store files, and how FMX implements support for them, but I suspect the answer will be yes for them as well. Edited June 30, 2023 by Remy Lebeau Share this post Link to post