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.
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