tags:

views:

194

answers:

1

Hello all

im new to delphi and EmbeddedWB1 , i really don't understand where is my source have problem.

very simple but can't work correctly,

my problem is in my delphi source EmbeddedWB1.ReadyState <> READYSTATE_INTERACTIVE not work

correctly. there is login form exist

in this site(http://sports.khan.co.kr/htdocs/login/login.html)

and if navigate this page, it not working correctly with

EmbeddedWB1.ReadyState <> READYSTATE_INTERACTIVE because webpage navigate too fast,

so login form element couldn't detected by Embeddedbwb1 and error happened.

anyone can help me ? what is problem? thanks in advance

      begin
        //WB := EmbeddedWB;
        forms := EmbeddedWB1.doc2.Forms as IHTMLElementCollection;
        theForm := forms.Item(0,'') as IHTMLFormElement;

        EmbeddedWB1.Navigate('http://sports.khan.co.kr/htdocs/login/login.html');
        while EmbeddedWB1.ReadyState <> READYSTATE_INTERACTIVE do
        begin
        Application.ProcessMessages;
          Sleep(500);
        end;
          with EmbeddedWB1 do
          begin
            EmbeddedWB1.OleObject.Document.GetElementByID('uid').Value := 'loginid';
            EmbeddedWB1.OleObject.Document.GetElementByID('upw').Value := 'password';
            EmbeddedWB1.OleObject.Document.forms.item(1).submit();

          end;
      end;
+1  A: 

Rather than use application.processmessages in a loop, why not use the OnNavigateComplete event and then fire your login inside that event if your in the correct state. To set up for this, create a new enumerated type NavigationState = (nsUnknown,nsLoginRequested) then right before your navigate to the login, set an instance variable of navigationstate to nsLoginRequested. In your OnNavigateComplete, if the state variable is nsLoginRequested then process the login and reset the state variable to nsUnknown (or the next step in your state).

This is a simple state engine pattern, and eliminates the loop completely.

skamradt