>              wbZillower.Navigate( URL );
>              Doc := wbZillower.Document as IHTMLDocument2; {***********}
> How can I get wbZillower.Document to be non nil in the procedure below?:

Because Navigate() is asynchronous. You get control back long before the 
navigator has loaded the page.
You have to wait until the page is loaded.

Before accessing the document, do something like this:
        while wbZillower.ReadyState < READYSTATE_INTERACTIVE do
            Application.ProcessMessages;

--
francois.pie...@overbyte.be
The author of the freeware multi-tier middleware MidWare
The author of the freeware Internet Component Suite (ICS)
http://www.overbyte.be


----- Original Message ----- 
From: "Rich Cooper" <r...@englishlogickernel.com>
To: "'Borland's Delphi Discussion List'" <delphi@elists.org>
Sent: Thursday, February 19, 2009 7:44 PM
Subject: RE: [TWebBrowser] Calling a JavaScript function


Francois et al,

I still have a problem with the line

              Doc := wbZillower.Document as IHTMLDocument2; {***********}

In the procedure below because wbZillower.Document is always nil, no matter
What the URL line is.

How can I get wbZillower.Document to be non nil in the procedure below?:




const Header : string = 'http://www.zillow.com/homes/map/';

procedure TfmZillower.buNextClick(Sender: TObject);
var I   : Integer;
    URL : WideString;
    Doc     : IHTMLDocument2; // Current HTML document
    HTMLWin : IHTMLWindow2;   // Parent window of current HTML document
begin
  Line := '';
  {Get values of each address}
  while (not Eof(AdrFile))
  do begin
       ReadLn(AdrFile,Line);
       Line := Trim(Line);
       if   Line<>''
       then begin
              for I := 1 to Length(Line) do
              if   Line[I]=' '
              then Line[I]:= '-';
              URL := Header+Line+'_rb/';
              meZillower.Text := URL;
              wbZillower.Navigate( URL );


              Doc := wbZillower.Document as IHTMLDocument2; {***********}
              if   Assigned(Doc)
              then begin
                     HTMLWin := Doc.parentWindow;
                     if   Assigned(HTMLWin)
                     then begin
                            try
                              HTMLWin.execScript( JavaScriptExpression,

'JavaScript');
                            except on E:Exception do
                              begin
                                ShowMessage( 'Javascript execution error: "'
+
                                        JavaScriptExpression + '"');
                              end;
                            end;
                          end;
                   end;
            end;
     end;
end;



Sincerely,
Rich Cooper
EnglishLogicKernel.com
Rich AT EnglishLogicKernel DOT com



-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Francois Piette
Sent: Wednesday, February 18, 2009 12:41 AM
To: Borland's Delphi Discussion List
Subject: Re: [TWebBrowser] Calling a JavaScript function

>What unit has to be in the "uses" clause to define the two vars:
>    Doc     : IHTMLDocument2; // Current HTML document
>    HTMLWin : IHTMLWindow2;   // Parent window of current HTML document

You need MSHTML, SHDocVw and ActiveX.

--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be


-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Francois Piette
Sent: Monday, February 16, 2009 7:25 AM
To: Borland's Delphi Discussion List
Subject: Re: [TWebBrowser] Calling a JavaScript function

> I have the following problem: Having a web page loaded into a TWebBrowser
> hosted in my Delphi application, I want to have Delphi code execute a
> JavaScript function embedded in the HTML page. How can I do that ?

Answering my own question:

procedure WB_ExecScript(WebBrowser: TWebBrowser; JavaScriptExpression :
String);
var
    Doc     : IHTMLDocument2; // Current HTML document
    HTMLWin : IHTMLWindow2;   // Parent window of current HTML document
begin
    Doc := WebBrowser.Document as IHTMLDocument2;
    if Assigned(Doc) then begin
        HTMLWin := Doc.parentWindow;
        if Assigned(HTMLWin) then begin
            try
                HTMLWin.execScript(JavaScriptExpression, 'JavaScript');
            except
                on E:Exception do begin
                    ShowMessage('Erreur d''exécution JavaScript de "' +
                                JavaScriptExpression + '"');
                end;
            end;
        end;
    end;
end;

--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi 

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to