TWebBrowser与嵌入式Youtube剪辑崩溃

kob*_*bik 5 delphi webbrowser-control delphi-5 flashplayer-10 twebbrowser

这是我的代码:

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

implementation
uses ActiveX;

procedure TForm1.Button1Click(Sender: TObject); // method 1
var
  HtmlFile: string;
begin
  HtmlFile := ExtractFilePath(Application.ExeName) + 'test.html';
  WebBrowser1.Navigate(HtmlFile);
end;

procedure LoadHtml(wb: TWebBrowser; HTMLStr: string);
var
  aStream: TMemoryStream;
begin
  wb.Navigate('about:blank'); // reset the webbrowser
  while wb.ReadyState < READYSTATE_INTERACTIVE do // wait to load the empty page
    Application.ProcessMessages;
  if Assigned(wb.Document) then
  begin
    aStream := TMemoryStream.Create;
    try
      aStream.WriteBuffer(Pointer(HTMLStr)^, Length(HTMLStr));
      aStream.Seek(0, soFromBeginning);
      (wb.Document as IPersistStreamInit).Load(TStreamAdapter.Create(aStream));
    finally
      aStream.Free;
    end;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject); // method 2
begin
  LoadHtml(WebBrowser1,
    '<html><head></head><body>'+
    '  <object width="640" height="390"> '+
    '  <param name="movie" value="http://www.youtube.com/v/L7NWdxFAHdY&hl=en_US&feature=player_embedded&version=3"> '+
    '  </param><param name="allowFullScreen" value="true"> '+
    '  </param><param name="allowScriptAccess" value="always"> '+
    '  </param><embed src="http://www.youtube.com/v/L7NWdxFAHdY&hl=en_US&feature=player_embedded&version=3" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"> '+
    '  </embed></object> '+
    '</body></html>'
    );
end;
Run Code Online (Sandbox Code Playgroud)

的test.html

<object width="425" height="349">
<param name="movie" value="http://www.youtube.com/v/1hPxGmTGarM?version=3&amp;hl=iw_IL">
</param><param name="allowFullScreen" value="true"></param>
<param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/1hPxGmTGarM?version=3&amp;hl=iw_IL" type="application/x-shockwave-flash" width="425" height="349" allowscriptaccess="always" allowfullscreen="true">
</embed></object>
Run Code Online (Sandbox Code Playgroud)

我的应用程序在两种方法中都崩溃了.我得到一个未处理的win32异常(由Flash播放器引起Exception EInvalidOp in module Flash10u.ocx at 00108657. Invalid floating point operation).

  • 我在D5,D7,D9上尝试了这段代码.
  • 我试图重新导入SHDocVw.dll.
  • 我也尝试使用EmbeddedWB控件而不是TWebBroser ...
  • Internet Explorer/Avant/Maxthon对此HTML没有任何问题(全部基于IE ActiveX).

任何建议或修复?

如何捕获此错误甚至抑制它?

有没有办法通过TWebBrowser事件动态操作或更改HTML,所以我可以显示图像而不是Flash播放器,就像Ad-Blockers一样?(我的客户通过互联网在他们的网站上拥有该代码,我的Delphi应用程序提供快速预览)

UPDATE

我使用TTimer启用/禁用FPU(基于Arjen的想法):

function Get8087CW: Word; // for D5
asm
        PUSH    0
        FNSTCW  [ESP].Word
        POP     EAX
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Timer1.Enabled := False;
  Timer1.Interval := 5000; // 5 sec
  Saved8087CW := Get8087CW;
end;

procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
begin
  Timer1.Enabled := False;
  System.Set8087CW($133F); // Disable all fpu exceptions
end;

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
   Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled := False;
  Set8087CW(Saved8087CW);
end;
Run Code Online (Sandbox Code Playgroud)

更新(2)

我最终在应用程序启动时屏蔽了FPU异常.从那时起,我的申请就没有(已知)影响.

Ser*_*lyk 5

一个更美丽的解决方案:

Math.SetExceptionMask([exInvalidOp, exDenormalized, exZeroDivide, exOverflow,
  exUnderflow, exPrecision]);
Run Code Online (Sandbox Code Playgroud)

如果我正确阅读文档,请保持所提到的Math.SetExceptionMask每个例外.

然而,它只是@ Arjen的方法更清洁,更漂亮的版本.


Arj*_*pek 4

尝试使用 Set8087CW(0x133f) 暂时禁用 FPU 异常; 信息