3

Delphi 6

ローカルのHTMLファイルを介してWebブラウザコントロール(TEmbeddedWB)をロードするコードがあります。ほとんどの場合正常に動作し、かなりの数年と数千人のユーザーがいます。

しかし、ある種のGoogle翻訳を行うスクリプトを含む特定のエンドユーザーページがあります。これにより、ページの読み込みに65秒以上の非常に長い時間がかかります。

ページを再読み込みしたり、アプリを終了したりできるように、ウェブブラウザを停止/中止/終了しようとしています。しかし、やめられないようです。停止を試し、about:blankを読み込んでみましたが、停止しないようです。

wb.Navigate(URL, EmptyParam, EmptyParam, EmptyParam, EmptyParam );
while wb.ReadyState < READYSTATE_INTERACTIVE do Application.ProcessMessages;

アプリは、65秒以上の非常に長い時間ReadyStateループ(ReadyState = READYSTATE_LOADING)に留まります。

誰か提案がありますか?

4

1 に答える 1

3

を使用している場合TWebBrowserは、TWebBrowser.Stopまたは必要に応じてIWebBrowser2.Stop、この目的に適した適切な機能です。この小さなテストを実行して、ページへのナビゲーションが停止するかどうかを確認してください (もちろん、ナビゲーションに約 100 ミリ秒かかる場合:)

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := False;
  WebBrowser1.Navigate('www.example.com');
  Timer1.Interval := 100;
  Timer1.Enabled := True;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if WebBrowser1.Busy then
    WebBrowser1.Stop;
  Timer1.Enabled := False;
end;

あなたが話しているのであれば、変更を待つのではなくTEmbeddedWB、関数を見てください。唯一のパラメーターとして、ミリ秒単位でタイムアウト値を指定する必要があります。次に、イベントを処理し、必要に応じてナビゲーションを中断できます。WaitWhileBusyReadyStateOnBusyWait

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;
于 2012-01-23T20:30:12.317 に答える