Einzelnen Beitrag anzeigen

daywalker9

Registriert seit: 1. Jan 2010
Ort: Leer
594 Beiträge
 
Delphi XE3 Professional
 
#2

AW: Delphi XE3 FMX Standardbrowser öffnen

  Alt 23. Dez 2012, 21:43
Du wirst mit ifdefs arbeiten müssen.

Unter OSX kannst so eine URL öffnen:

Delphi-Quellcode:
Workspace := TNSWorkspace.create;
Workspace.openURL(...);
Workspace.free;
//Edit: Ich hab mir sowas gebastelt, in XE3 kann man ja PlatformServices registrieren:

Delphi-Quellcode:
unit FMX.PlatformExtensions;

interface

type
  IFMXOpenWebbrowser = interface['{9CA18562-C56D-489C-AE97-D069B9C58427}']
    function OpenURL(const AURL: String) : boolean;
  end;

implementation

uses
{$IFDEF MACOS}
  FMX.PlatFormExtensions.Mac
{$ELSE IF WINDOWS}
  FMX.PlatformExtensions.Win
{$ENDIF}
  ;
end.
Delphi-Quellcode:
unit FMX.PlatformExtensions.Mac;

interface

implementation

uses
  IdURI,
  MacApi.Foundation,
  MacApi.AppKit,
  FMX.PlatForm,
  FMX.PlatFormExtensions;

type
  TFMXOpenWebbrowser = class(TInterfacedObject, IFMXOpenWebbrowser)
  public
    function OpenURL(const AURL: string): Boolean;
  end;



{ TFMXOpenWebbrowser }

function TFMXOpenWebbrowser.OpenURL(const AURL: string): Boolean;
begin
  TNSWorkspace.Wrap(TNSWorkspace.OCClass.sharedWorkspace)
    .openURL(
      TNSURL.Wrap(
        TNSURL.OCClass.URLWithString(NSSTR(TIdURI.URLEncode(AURL)))
      )
    );
end;

initialization

  TPlatformServices.Current.AddPlatformService(IFMXOpenWebbrowser, TFMXOpenWebbrowser.Create());
Delphi-Quellcode:
unit FMX.PlatformExtensions.Win;

interface

implementation

uses
  ShellAPI,
  WinApi.Windows,
  FMX.PlatForm,
  FMX.PlatFormExtensions;

type
  TFMXOpenWebbrowser = class(TInterfacedObject, IFMXOpenWebbrowser)
  public
    function OpenURL(const AURL: string): Boolean;
  end;



{ TFMXOpenWebbrowser }

function TFMXOpenWebbrowser.OpenURL(const AURL: string): Boolean;
begin
  ShellExecute(0, 'open', pChar(AURL), nil, nil, SW_SHOW);
end;

initialization

  TPlatformServices.Current.AddPlatformService(IFMXOpenWebbrowser, TFMXOpenWebbrowser.Create());



end.
Und zum Testen:

Delphi-Quellcode:
uses
  FMX.PlatFormExtensions;

procedure TForm50.Button1Click(Sender: TObject);
var
  lOpenWeb: IFMXOpenWebbrowser;
begin
  lOpenWeb := IFMXOpenWebbrowser(TPlatformServices.Current.GetPlatformService(IFMXOpenWebbrowser));
  if lOpenWeb <> nil then
    lOpenWeb.OpenURL(Edit1.Text);

end;
Lars

Geändert von daywalker9 (23. Dez 2012 um 22:46 Uhr)
  Mit Zitat antworten Zitat