With Firemonkey 2 (FM²) which was introduced with Delphi XE3 the global variable Platform was refactured to a kind of service registry. You acquire a specific service which may or may not be available on your current platform via
TPlatformServices.Current.SupportsPlatformService(ServiceGUID, ServiceInterface)
This function returns True if the service is available and an interface reference to that service.
The Problem
The returned interface is an IInterface and not the type of the requested service. To set the clipboard content you need to write something like this
var
ServiceIntf: IInterface;
...
if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, ServiceIntf) then
(ServiceIntf as IFMXClipboardService).SetClipboard('Hello');
Handy Helper
How about simply writing that:
var
Service: IFMXClipboardService;
...
if SupportsPlatformService(IFMXClipboardService, Service) then
Service.SetClipboard('Hello');
this is exactly what following unit provides:
unit FMX.Platform.Tools;
interface
function SupportsPlatformService(const ServiceGUID: TGUID; out Service): Boolean;
implementation
uses
FMX.Platform;
function SupportsPlatformService(const ServiceGUID: TGUID; out Service): Boolean;
var
ServiceIntf: IInterface;
begin
Result := TPlatformServices.Current.SupportsPlatformService(ServiceGUID, ServiceIntf);
if Result then
ServiceIntf.QueryInterface(ServiceGUID, Service) else
IInterface(Service) := nil;
end;
end.
The respective author is responsible for articles (snaptips) within this service.
Leave a comment
You need to be logged in to leave a commentLogin