was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

41 Visitors Online


 
...lokale HTML-Dateien in einem TWebbrowser öffnen und Links direkt starten?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (17):  
     


{
  This example shows how to open local files in a TWebbrowser
  and start links directly without showing a Dialog.
}

{
  Dieses Beispiel zeigt, wie man lokale Dateien in einem TWebbrowser
  öffnen kann und wie man lokale Links direct ausführen kann ohne
  dass ein Dialog erscheint.
}


unit Unit1;

interface

uses
  
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw;

type
  
TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure WebBrowser1BeforeNavigate2(Sender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
  private
    
FIsStartPage: Boolean;
    { Private declarations }
  
public
    
{ Public declarations }
  
end;

var
  
Form1: TForm1;

implementation

{$R *.DFM}

uses
  
ShellApi;


// Open a local page:
procedure TForm1.Button1Click(Sender: TObject);
const
 
LOCAL_PAGE ='C:/StartPage.htm'
begin
  
FIsStartPage := True;
  Webbrowser1.Navigate('file:///' + LOCAL_PAGE);
  FIsStartPage := False;
end;


procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var
  
newURL: string;
begin
  
newURL := URL;
  // For local links, don't show a dialog but open the file directly
  
if (not FIsStartPage) and FileExists(newURL) then
  begin
    
Cancel := True;
    ShellExecute(Application.Handle, 'open', PChar(newURL), nilnil, SW_NORMAL);
  end;
end;



 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners