0

In my Delphi 12.1 VCL Application in Windows 11 Pro 64-bit I need a browser to render remote web pages from the Internet. So I dropped a TEdgeBrowser on my form to test it:

PAS file:

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Winapi.WebView2, Winapi.ActiveX,
  Vcl.Edge;

type
  TForm1 = class(TForm)
    EdgeBrowser1: TEdgeBrowser;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  EdgeBrowser1.Navigate('https://www.example.com');
end;

end.

DFM file:

object Form1: TForm1
  Left = 0
  Top = 0
  Margins.Left = 5
  Margins.Top = 5
  Margins.Right = 5
  Margins.Bottom = 5
  Caption = 'Form1'
  ClientHeight = 664
  ClientWidth = 938
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -18
  Font.Name = 'Segoe UI'
  Font.Style = []
  Position = poScreenCenter
  OnCreate = FormCreate
  PixelsPerInch = 144
  TextHeight = 25
  object EdgeBrowser1: TEdgeBrowser
    Left = 0
    Top = 0
    Width = 938
    Height = 664
    Margins.Left = 5
    Margins.Top = 5
    Margins.Right = 5
    Margins.Bottom = 5
    Align = alClient
    TabOrder = 0
    AllowSingleSignOnUsingOSPrimaryAccount = True
    TargetCompatibleBrowserVersion = '117.0.2045.28'
    UserDataFolder = '%LOCALAPPDATA%\bds.exe.WebView2'
    ExplicitLeft = 480
    ExplicitTop = 360
    ExplicitWidth = 150
    ExplicitHeight = 60
  end
end

I went to the Microsoft website:

https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section

and downloaded: MicrosoftEdgeWebview2Setup.exe

After running the Webview installer, it said:

Message shown after running the webview2 installer

When running my test application, it showed: Nothing!

What must I do to make this work?

11
  • 1
    Don't you need to put the web view DLL next to the EXE? Commented Sep 2 at 19:49
  • <off-topic rant>To me it's a mystery why it is so difficult to render hypertext content in a Win32 app these days. It used to be absolutely trivial when the old IE control was universally available (and which still powers the CHM viewer after almost 25 years!). Why do you need a PhD in the web view control these days?</off-topic rant> Commented Sep 2 at 19:51
  • @AndreasRejbrand Because Trident (aka "MSHTML") from MSIE isn't alive anymore - Edge uses Blink/Chromium nowadays. Back then things were done with HTML/CSS, but nowadays everything is bloated with JS. That aside I don't get why people insist on using MS's faulty Edge when they could use Chromium Embedded Framework = CEF4Delphi directly. Without any client installation.
    – AmigoJack
    Commented Sep 2 at 20:06
  • @AndreasRejbrand, I have placed WebView2Loader.dll next to the exe. It did not work. Commented Sep 2 at 20:07
  • 1
    @user1580348 Try WebView4Delphi and run a demo. It includes the right DLLs and you should be able to initialize the browser. Commented Sep 3 at 7:26

1 Answer 1

4

Per Embarcadero's documentation:

Using TEdgeBrowser Component and Changes to the TWebBrowser Component

It is not enough to just install the WebView2 control. You also need to install the WebView2 SDK so that you can copy its WebView2Loader.dll file into your app's folder (or anywhere else on the OS search path).

You also need to configure the browser's UserDataFolder property before you navigate to any URL.

Also, you should assign an OnCreateWebViewCompleted event handler to detect failures in initializing the WebView2 control. If you don't, you need to use the TApplication(Events).OnException event instead to catch the failure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.