2012-01-23 11 views
3

Delphi 6TWeBrowserナビゲーションの進行を中止する方法は?

ローカルHTMLファイルを介してWebブラウザーコントロール(TEmbeddedWB)をロードするコードがあります。ほとんどの場合、うまく動作し、ユーザー数千年と1000年の間です。

しかし、上向きに65秒のページをロードするために本当に長い時間がかかりますものを、翻訳しグーグルのいくつかの並べ替えを行いスクリプトを有する特定のエンドユーザーのページがあります。

私はウェブブラウザを作成しようとしています停止/中断/終了ページをリロードするか、アプリが終了できるようにします。しかし、私はそれを止めるように見えることはできません。私はStopについて試しましたが、about:blankをロードしていますが、停止していないようです。

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

アプリが上向きに65秒の、非常に長い時間のためのreadyStateのループ(のreadyState = READYSTATE_LOADING)に残っています。

誰もが何か提案がありますか?

+0

stopメソッドを使用するとどうなりますか? – EMBarbosa

+1

@TLama:私は同じ問題を抱えていて、あなたのソリューションは助けにならなかった...それはまだ 'ReadyState = READYSTATE_LOADING'に固執していて、' EmbeddedWB1.Stop; 'は役に立たない... – Legionar

答えて

3

TWebBrowserを使用している場合はTWebBrowser.Stop、またはIWebBrowser2.Stopをこの目的に適した機能にしたい場合は、TWebBrowser.Stopを使用してください。ナビゲーションはもちろんの100msの詳細がかかる場合(この小さなテストを行うと、それはあなたのページへのナビゲーションを停止したかどうかを確認するために試してみてください:)

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を話している場合は、代わりに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; 
関連する問題