Delphi - объектно-ориентированный язык программирования, разработанный компанией Borland в 1995 году. Он основан на языке программирования Pascal, но имеет более расширенные возможности и добавлены новые функции.
Delphi является интегрированной средой разработки (IDE), которая позволяет разрабатывать программное обеспечение для различных платформ, включая Windows, macOS, Android и iOS. Delphi достигает многоплатформенности с помощью...
{
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), nil
, nil
, SW_NORMAL);
end
;
end
;