Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 如何中止浏览器导航进程?_Delphi_Browser_Delphi 6 - Fatal编程技术网

Delphi 如何中止浏览器导航进程?

Delphi 如何中止浏览器导航进程?,delphi,browser,delphi-6,Delphi,Browser,Delphi 6,德尔菲6 我有一些代码可以通过本地HTML文件加载Webbrowser控件(TEmbeddedWB)。它在大多数情况下工作良好,并且已经有相当多的用户数年和1000个用户 但是有一个特定的终端用户页面有一个脚本,它执行某种谷歌翻译功能,这使得页面加载需要很长时间,高达65秒 我正在尝试使webbrowser停止/中止/退出,以便可以重新加载页面或退出应用程序。然而,我似乎无法阻止它。我试过停止,加载:blank,但似乎没有停止 wb.Navigate(URL, EmptyParam, Empty

德尔菲6

我有一些代码可以通过本地HTML文件加载Webbrowser控件(TEmbeddedWB)。它在大多数情况下工作良好,并且已经有相当多的用户数年和1000个用户

但是有一个特定的终端用户页面有一个脚本,它执行某种谷歌翻译功能,这使得页面加载需要很长时间,高达65秒

我正在尝试使webbrowser停止/中止/退出,以便可以重新加载页面或退出应用程序。然而,我似乎无法阻止它。我试过停止,加载:blank,但似乎没有停止

wb.Navigate(URL, EmptyParam, EmptyParam, EmptyParam, EmptyParam );
while wb.ReadyState < READYSTATE_INTERACTIVE do Application.ProcessMessages;
wb.Navigate(URL,EmptyParam,EmptyParam,EmptyParam,EmptyParam);
而wb.ReadyState
应用程序在ReadyState循环(ReadyState=ReadyState_加载)中保留相当长的时间,长达65秒

有人有什么建议吗?

如果您正在使用,或者如果您想要,则是适合此用途的正确功能。尝试做这个小测试,看看它是否会停止对页面的导航(当然,如果导航时间超过100毫秒:)

如果您正在谈论,请查看
WaitWhileBusy
函数,而不是等待
ReadyState
更改。作为唯一的参数,您必须以毫秒为单位指定超时值。然后,您可以处理
OnBusyWait
事件,并在需要时中断导航

procedure TForm1.Button1Click(Sender: TObject);
begin
  // navigate to the www.example.com
  EmbeddedWB1.Navigate('www.example.com');
  // and wait with WaitWhileBusy function for 10 seconds, at
  // this time the OnBusyWait event will be periodically fired;
  // you can handle it and increase the timeout set before by
  // modifying the TimeOut parameter or cancel the waiting loop
  // by setting the Cancel parameter to True (as shown below)
  if EmbeddedWB1.WaitWhileBusy(10000) then
    ShowMessage('Navigation done...')
  else
    ShowMessage('Navigation cancelled or WaitWhileBusy timed out...');
end;

procedure TForm1.EmbeddedWB1OnBusyWait(Sender: TEmbeddedWB; AStartTime: Cardinal;
  var TimeOut: Cardinal; var Cancel: Boolean);
begin
  // AStartTime here is the tick count value assigned at the
  // start of the wait loop (in this case WaitWhileBusy call)
  // in this example, if the WaitWhileBusy had been called in
  // more than 1 second then
  if GetTickCount - AStartTime > 1000 then
  begin
    // cancel the WaitWhileBusy loop
    Cancel := True;
    // and cancel also the navigation
    EmbeddedWB1.Stop;
  end;
end;

当你使用停止方法时会发生什么?@TLama:我也有同样的问题,而你的解决方案没有帮助。。。它仍然被阻塞在
ReadyState=ReadyState\u加载上,并且
EmbeddedWB1.Stop没有帮助。。。
procedure TForm1.Button1Click(Sender: TObject);
begin
  // navigate to the www.example.com
  EmbeddedWB1.Navigate('www.example.com');
  // and wait with WaitWhileBusy function for 10 seconds, at
  // this time the OnBusyWait event will be periodically fired;
  // you can handle it and increase the timeout set before by
  // modifying the TimeOut parameter or cancel the waiting loop
  // by setting the Cancel parameter to True (as shown below)
  if EmbeddedWB1.WaitWhileBusy(10000) then
    ShowMessage('Navigation done...')
  else
    ShowMessage('Navigation cancelled or WaitWhileBusy timed out...');
end;

procedure TForm1.EmbeddedWB1OnBusyWait(Sender: TEmbeddedWB; AStartTime: Cardinal;
  var TimeOut: Cardinal; var Cancel: Boolean);
begin
  // AStartTime here is the tick count value assigned at the
  // start of the wait loop (in this case WaitWhileBusy call)
  // in this example, if the WaitWhileBusy had been called in
  // more than 1 second then
  if GetTickCount - AStartTime > 1000 then
  begin
    // cancel the WaitWhileBusy loop
    Cancel := True;
    // and cancel also the navigation
    EmbeddedWB1.Stop;
  end;
end;