简体   繁体   English

TEmbeddedWB仍在加载页面,无法停止

[英]TEmbeddedWB is still loading page and cant be stopped

I was searching here on SO, but without success or any acceptable answer. 我在这里搜索SO,但是没有成功或任何可接受的答案。

I have bigger application, which is using TEmbeddedWB. 我有更大的应用程序,正在使用TEmbeddedWB。 Lets say my code is like this: 可以说我的代码是这样的:

// here is some other code where I am working with EmbeddedWB1

EmbeddedWB1.Navigate2('http://www.stackoverflow.com');

while EmbeddedWB1.ReadyState <> READYSTATE_COMPLETE do
begin
  EmbeddedWB1.Stop;
  Application.ProcessMessages;
end;

EmbeddedWB1.Navigate2('http://www.google.com');

And this code is stuck inside that loop. 这段代码被卡在那个循环中。

When debugging, EmbeddedWB1.ReadyState = READYSTATE_LOADING . 调试时, EmbeddedWB1.ReadyState = READYSTATE_LOADING

Could somebody tell me, how to definitelly stop loading of page, and move on to the next navigate? 有人可以告诉我,如何确定停止页面加载,然后继续进行下一个导航吗?

Thanks a lot. 非常感谢。

PS: without that loop, it can normally load another page, fe google.com. PS:如果没有该循环,通常可以加载另一个页面,例如google.com。 But I really need to have it in READYSTATE_COMPLETE before loading another page. 但是我真的需要在加载另一个页面之前将它放在READYSTATE_COMPLETE

It's not exiting the loop because you're specifically telling it not to do so until the ReadyState is READYSTATE_COMPLETE , and then calling Stop so it can never reach that ReadyState . 它不会退出循环,因为您明确地告诉它在ReadyStateREADYSTATE_COMPLETE之前不要这样做,然后调用Stop使其永远无法到达该ReadyState

Follow the logic: 遵循逻辑:

  • The line I've marked as { 1 } says "Stay in the loop until ReadyState is READYSTATE_COMPLETE". 我标记为{ 1 }的行显示为“保持循环,直到ReadyState为READYSTATE_COMPLETE”。
  • The line I've marked as { 2 } says "Stop loading the page", which means ReadyState can never be READYSTATE_COMPLETE 我标记为{ 2 }的行显示“停止加载页面”,这意味着ReadyState 永远不能READYSTATE_COMPLETE
// This line says "Stay in loop until we reach READYSTATE_COMPLETE
    while EmbeddedWB1.ReadyState  READYSTATE_COMPLETE do   { 1 }
    begin
      EmbeddedWB1.Stop; { 2 }
      Application.ProcessMessages;
    end;

You're intentionally preventing your loop from exiting. 您有意阻止循环退出。

If you want to actually stop loading the page and exit the loop, put in a counter or timer, and add a condition to the loop to allow you to exit if the condition is met: 如果您想真正停止加载页面并退出循环,请放入计数器或计时器,然后向循环中添加条件以允许您在满足条件时退出:

Counter := 1;
while (Counter < SomeValue) and (EmbeddedWB1.ReadyState <> READYSTATE_COMPLETE) do
begin
  Inc(Counter);
  Application.ProcessMessages;
end;

if Counter >= SomeValue then
  EmbeddedWB1.Stop;   // Had to break the loop above before complete. 
                      // trying to load and move on.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM