使用 Delphi 在运行时创建 TWebBrowser
我有一个 TWebBrowser 对象,它是在运行时创建并在后台使用的,即不可见。问题是像 OnDocumentComplete 这样的事件在 Delphi2009 中不起作用或不会被触发。有什么建议吗?
procedure TfrmMain.FormCreate(Sender: TObject);
begin
FWebBrowser:= TWebBrowser.Create(Self);
FWebBrowser.RegisterAsBrowser:= True;
FWebBrowser.OnDocumentComplete:= WhenDocIsCompleted;
end;
procedure TfrmMain.WhenDocIsCompleted(ASender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
begin
ShowMessage('Doc is completed!');
end;
Navigate 和 Navigate2 之间有什么重要的区别吗?我怎样才能在这里启用cookies?
提前致谢。
I have a TWebBrowser object which is created in runtime and used in background, that is, not visible. The problem is that events like OnDocumentComplete dont work or are not triggered in Delphi2009. Any advice?
procedure TfrmMain.FormCreate(Sender: TObject);
begin
FWebBrowser:= TWebBrowser.Create(Self);
FWebBrowser.RegisterAsBrowser:= True;
FWebBrowser.OnDocumentComplete:= WhenDocIsCompleted;
end;
procedure TfrmMain.WhenDocIsCompleted(ASender: TObject; const pDisp: IDispatch;
var URL: OleVariant);
begin
ShowMessage('Doc is completed!');
end;
There is any difference important between Navigate and Navigate2? How can I enable cookies here?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可能会遇到此问题,因为 TWebBrowser 在内部与父窗体的句柄紧密配合以获取从窗口发布的消息。尝试在 TWebBrowser 打开时使用隐藏表单(也可以选择运行时创建),和/或调查 HandleAllocation 和 HandleNeeded 方法是否可以帮助您。
You may have this issue because the TWebBrowser internally works closely together with the handle of the parent form to get messages posted from windows. Try using a hidden form with the TWebBrowser on (optionally run-time created as well), and/or investigate if the HandleAllocated and HandleNeeded methods could help you.
调用 OnDocumentComplete 问题:
或者在您的情况下:
在 webBrowser.Navigate 之前
Call for the OnDocumentComplete Problem:
or in your case:
before webBrowser.Navigate
与网页 cookie 完美配合的组件是来自 EmbeddedWB 的 TEmbeddedWB,并且是免费的。
A component working perfectly with web-pages cookies is TEmbeddedWB from EmbeddedWB and is free.