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 meansReadyState
can never beREADYSTATE_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.