OLE Control window handle error with WebBrowser and Delphi 2007

梦想与她 提交于 2019-12-02 19:34:44

问题


I have run into an issue a couple of weeks ago that appear to have no logical explanation. I'm building an application with Delphi 2007 using AlphaControls and a WebBrowser component placed on a form. The TWebBrowser fetches a banner from the web and displays it into the UI. bad thing is that as soon as the form with the banner is displayed, I get the "Could not obtain OLE Control window handle", while the browser is being displayed outside of the form, in the top left corner of the desktop.

I've been trying basically anything to figure it out, but the debugger does not provide too much information about what's going on (that's all I get: First chance exception at $770C4B32. Exception class EOleError with message 'Could not obtain OLE control window handle'. Process project1.exe (3700)). Funny thing is that the same TWebBrowser on Form1 of a new project works without any issues.

Any thoughts on that would be highly appreciated.


回答1:


It is caused by the html form being closed. The vendor's forums show some code that will fix the problem. http://www.bsalsa.com/forum/showthread.php?t=255

Set Cancel to True in the OnWindowClosing event and navigate to an empty page if it is the main webbrowser. In case your webbrowser is a popup window, you may want to close the form the EWB is on.

procedure TForm2.EmbeddedWB1WindowClosing(ASender: TObject; IsChildWindow: WordBool; var Cancel: WordBool);
begin
  Cancel := True;
  (ASender as TEmbeddedWB).GoAboutBlank;
end;


来源:https://stackoverflow.com/questions/13351714/ole-control-window-handle-error-with-webbrowser-and-delphi-2007

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!