Jump to content
FabDev

Clipboard how to detect it contain files on Firemonkey ?

Recommended Posts

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 by FabDev

Share this post


Link to post
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 by Remy Lebeau

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×