delphi TWebBrowser与嵌入Youtube视频崩溃


本文整理自网络,侵删。

 type
  TForm1 = class(TForm)
    WebBrowser1TWebBrowser;
    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;

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>

My application crashes in both methods. I get An unhandled win32 exception (caused by Flash player Exception EInvalidOp in module Flash10u.ocx at 00108657. Invalid floating point operation).

I tried this code on D5D7D9.
I tried to re-import SHDocVw.dll.
I also tried to use EmbeddedWB control instead of TWebBroser...
Internet Explorer/Avant/Maxthon has no problems with this HTML (all based on IE ActiveX).
Any suggestions or a fix?

How can I catch this error or even suppress it?

Is there a way to manipulate or change the HTML on the fly via a TWebBrowser eventso I can display an Image instead of the Flash playersame as Ad-Blockers works? (My customers have that code in their sites over the internetand my Delphi application provides a fast preview)

UPDATE

I used a TTimer to enable/disable FPU (based on Arjen's idea):


解决办法:

function Get8087CWWord; // 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;

相关阅读 >>

Delphi tlog 日志

Delphi编写系统服务

Delphi重写一个字符串分割函数

Delphi 游戏测试call

Delphi app如何禁掉安卓锁屏

Delphi 如何设置热键

Delphi fmx获取屏幕方向

Delphi 批量把图片保存到access数据库

Delphi 操作键盘按下和释放操作

Delphi nethttpclient post 函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...