事件没有被解雇

时间:2015-02-05 14:38:10

标签: delphi delphi-xe7 twebbrowser

我正在尝试使用WebWorkerStarted中的WebWorkerFinishedTWebbrowser,但这些事件根本不会被解雇。

如何让这些活动有效?我想看看哪些工作线程是从TWebbrowser启动的。

unit Unit2;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.OleCtrls, SHDocVw;

type
  TForm2 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure WebBrowser1WebWorkerFinsihed(ASender: TObject; dwUniqueID: Cardinal);
    procedure WebBrowser1WebWorkerStarted(ASender: TObject; dwUniqueID: Cardinal; const bstrWorkerLabel: WideString);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate('www.stackoverflow.com');
end;

procedure TForm2.WebBrowser1WebWorkerFinsihed(ASender: TObject; dwUniqueID: Cardinal);
begin
  // does not fire
end;

procedure TForm2.WebBrowser1WebWorkerStarted(ASender: TObject; dwUniqueID: Cardinal; const bstrWorkerLabel: WideString);
begin
  // does not fire
end;

end.

1 个答案:

答案 0 :(得分:6)

记录在案here

  

默认情况下,即使运行时环境安装了最新的IE(例如,IE11),TWebBrowser也会使用IE7标准模式。

WebWorkers是在IE10中引入的,因此您必须让IE以更新的模式运行。至少需要设置两个注册表项(如果同时支持32/64位,则更多):

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) 
  {\Wow6432Node}
  \SOFTWARE
  \Microsoft 
  \Internet Explorer
  \Main
  \FeatureControl
  \FEATURE_BEHAVIORS
     {NEW DWORD ->  'YourApplication.exe'
     {    VALUE -> 1  

另外(例如,IE11模式)

  HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER) 
  {\Wow6432Node}
  \SOFTWARE
  \Microsoft 
  \Internet Explorer
  \Main
  \FeatureControl
  \FEATURE_BROWSER_EMULATION
     {NEW DWORD ->  'YourApplication.exe'
     {    VALUE ->  0x2AF8 

这将导致由TWebBrowser包装的Internet Explorer实例以IE11模式运行,支持WebWorkers等。在设置此值之前,您应该对安装的IE版本进行某种健全性检查。有关有效条目的更多信息can be found on MSDN

导航到StackOverflow时,这仍然不会为我引发任何WebWorker事件(你确定它会使用它们吗?)。作为验证测试​​,此WebWorkers演示页面确实引发了OnWebWorkerStarted事件:

WebBrowser1.Navigate('https://whatwg.org/demos/workers/primes/page.html');