Question

I was searching here on SO, but without success or any acceptable answer.

I have bigger application, which is using 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.

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, f.e. google.com. But I really need to have it in READYSTATE_COMPLETE before loading another page.

Was it helpful?

Solution

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.

Follow the logic:

  • The line I've marked as { 1 } says "Stay in the loop until ReadyState is READYSTATE_COMPLETE".
  • The line I've marked as { 2 } says "Stop loading the page", which means ReadyState can never be 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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top