FireMonkey Platform Services
Go Up to FireMonkey Applications Guide
A platform service is a FireMonkey interface that defines some functionality that might or might not be implemented on a particular run-time platform.
FireMonkey implements many platform services, and you can implement your own platform services.
Contents
Using a Platform Service
To use a platform service, you must:
- Add a reference to the unit where your service is declared, such as FMX.Platform, to your unit.
- Call TPlatformServices.SupportsPlatformService with the target platform service as a parameter to determine whether or not the specified platform service is supported at run time.
- If
SupportsPlatformService
returnsTrue
, use TPlatformServices.GetPlatformService to access the actual platform service, and cast the returned service appropriately. You can alternatively useSupportsPlatformService
to obtain the service as well.
For example, to access the clipboard service (IFMXExtendedClipboardService):
Delphi:
var
ClipboardService: IFMXExtendedClipboardService;
begin
if TPlatformServices.Current.SupportsPlatformService(IFMXExtendedClipboardService, ClipboardService) then
begin
// …
end;
end;
C++:
_di_IFMXClipboardService ClipboardService;
if (TPlatformServices::Current->SupportsPlatformService(__uuidof(IFMXClipboardService), &ClipboardService)) {
// …
}
Built-in Platform Services
Registering and Unregistering Platform Services
You can use TPlatformServices.AddPlatformService and TPlatformServices.RemovePlatformService to register and unregister platform services, respectively.
For example, you can unregister one of the built-in platform services and replace it with a new implementation of the platform service that is tailored to fit your needs.