Search code examples
delphibrowserdelphi-xe2firemonkey

How to open an URL with the default browser with FireMonkey cross-platform applications?


Usually, I use: ShellExecute(0, 'OPEN', PChar(edtURL.Text), '', '', SW_SHOWNORMAL);

How can I have the same behaviour (opening a link in the default browser), on all platforms (Windows and OSX)?


Solution

  • In the FireMonkey discussion forum I found this code for a question about NSWorkspace.URLForApplicationToOpenURL:

    uses
      Posix.Stdlib;
    ....
      _system(PAnsiChar('open ' + ACommand));
    

    (not tested by me)


    Update: Posix is not available on Windows so it is not possible to write a solution which uses the same OS calls on all platforms. I suggest to move such code in a central 'XPlatform' unit which has some IFDEF POSIX etc.