🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.delphi.com.activex.using
Article #166

TWebBrowser

#166
From: Mark Moss
Date: Wed, 23 Jul 2008 03:19
314 lines
10306 bytes
Help

        I have the following code which should work, but does not

        If I run it straight from Internet Explorer it works fine, but if I 
run it thru TWebBrowser I get the following error.

        Line 17
        Char 44
        'GMap2' is undefined
        Code  0
        URL    about:blank


        Any help that you guys can give would be greatly appreciated.

Thanks





Test08.html
{------------------------------------------------------------------------------------------------------------}


 <!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
   <head>
     <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
     <title>Google Maps JavaScript API Example</title>
     <script
            src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAACpomf__h59zOpwlPj8I1TxRvlRs7GQV6IzvBJzRL3vQC1yP8vhT5o5kvyXKxB8bl02zs_dkZYyndHg" 
type="text/javascript">
     </script>
     <script type="text/javascript">
     // Create a directions object and register a map and DIV to hold the
     // resulting computed directions
     var map;
     var directionsPanel;
     var directions;
            function initialize() {
             if ( GBrowserIsCompatible() ) {
                                            map = new 
GMap2(document.getElementById("map_canvas"));
                                            map.setCenter(new GLatLng( 
38.932400, -104.785600 ), 14 );
                                            directionsPanel = 
document.getElementById("route");
                                            directions = new 
GDirections(map, directionsPanel);
                                            directions.load("from 
38.932400, -104.785600  to  38.930400, -104.786600" );
                                           }
                                  }
     </script>
   </head>
   <body onload="initialize()">
     <div id="map_canvas" style="width: 350px; height: 350px; float:left; 
border: 1px solid black;"></div>
     <div id="route"      style="width: 350px; height: 350px; float:left; 
border; 1px solid black;"></div>
     <br/>
   </body>
 </html>';



Project File

Project1.dpr
{------------------------------------------------------------------------------------------------------------}


program Project1;

uses
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.



Delphi Test Program

Unit1.pas
{------------------------------------------------------------------------------------------------------------}


unit KioskMapDirections;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, AdvGlowButton, ExtCtrls, Shader, SR4UProc,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;

type
  TfrmKioskMapDirections = class(TForm)
    Shader1: TShader;
    pnlMainMenu: TPanel;
    agbMainMenu: TAdvGlowButton;
    pnlSubMenu: TPanel;
    agbSubMenu: TAdvGlowButton;
    pnlDetailMenu: TPanel;
    agbDetailMenu: TAdvGlowButton;
    pnlDescription: TPanel;
    agbDescription: TAdvGlowButton;
    WebBrowser: TWebBrowser;
    IdHTTP1: TIdHTTP;
    procedure agbMainMenuClick(Sender: TObject);
    procedure agbSubMenuClick(Sender: TObject);
    procedure agbDetailMenuClick(Sender: TObject);
    procedure agbDescriptionClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmKioskMapDirections: TfrmKioskMapDirections;

implementation

uses
   MSHTML, ACTIVEX;

{$R *.dfm}

const
   rootDoc: String =
       '<!DOCTYPE html "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'#13#10 +
       '<html xmlns="http://www.w3.org/1999/xhtml">'#13#10 +
       '  <head>'#13#10 +
       '    <meta http-equiv="content-type" content="text/html; 
charset=utf-8"/>'#13#10 +
       '    <title>Google Maps JavaScript API Example</title>'#13#10 +
       '    <script'#13#10 +
       ' 
src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAACpomf__h59zOpwlPj8I1TxRvlRs7GQV6IzvBJzRL3vQC1yP8vhT5o5kvyXKxB8bl02zs_dkZYyndHg" 
type="text/javascript">'#13#10 +
       '    </script>'#13#10 +
       '    <script type="text/javascript">'#13#10 +
       '    // Create a directions object and register a map and DIV to hold 
the'#13#10 +
       '    // resulting computed directions'#13#10 +
       '    var map;'#13#10 +
       '    var directionsPanel;'#13#10 +
       '    var directions;'#13#10 +
       '           function initialize() {'#13#10 +
       '            if ( GBrowserIsCompatible() ) {'#13#10 +
       '                                           map = new 
GMap2(document.getElementById("map_canvas"));'#13#10 +
       '                                           map.setCenter(new 
GLatLng( 38.932400, -104.785600 ), 14 );'#13#10 +
       '                                           directionsPanel = 
document.getElementById("route");'#13#10 +
       '                                           directions = new 
GDirections(map, directionsPanel);'#13#10 +
       '                                           directions.load("from 
38.932400, -104.785600  to  38.930400, -104.786600" );'#13#10 +
       '                                          }'#13#10 +
       '                                 }'#13#10 +
       '    </script>'#13#10 +
       '  </head>'#13#10 +
       '  <body onload="initialize()">'#13#10 +
       '    <div id="map_canvas" style="width: 350px; height: 350px; 
float:left;  border: 1px solid black;"></div>'#13#10 +
       '    <div id="route"      style="width: 350px; height: 350px; 
float:left;  border; 1px solid black;"></div>'#13#10 +
       '    <br/>'#13#10 +
       '  </body>'#13#10 +
       '</html>';

{==============================================================================}

procedure TfrmKioskMapDirections.agbMainMenuClick(Sender: TObject);
begin

     GlobalReturnCode                            := 90;

     Close;

end;

{==============================================================================}

procedure TfrmKioskMapDirections.agbSubMenuClick(Sender: TObject);
begin

     GlobalReturnCode                            := 80;

     Close;

end;

{==============================================================================}

procedure TfrmKioskMapDirections.agbDetailMenuClick(Sender: TObject);
begin

     GlobalReturnCode                            := 70;

     Close;

end;

{==============================================================================}

procedure TfrmKioskMapDirections.agbDescriptionClick(Sender: TObject);
begin

     GlobalReturnCode                            := 60;

     Close;

end;

{==============================================================================}

procedure TfrmKioskMapDirections.FormShow(Sender: TObject);
var
  v                                              : Variant;
  HTMLDocument                                   : IHTMLDocument2;

begin

     Webbrowser.Navigate('about:blank');

     while WebBrowser.ReadyState < READYSTATE_INTERACTIVE do
          Application.ProcessMessages;

     HTMLDocument := WebBrowser.Document as IHTMLDocument2;

     if (assigned(HtmlDocument)) then
       begin
            v := VarArrayCreate([0, 0], varVariant);
            v[0] := rootDoc; // Here's your HTML string
            HTMLDocument.Write(PSafeArray(TVarData(v).VArray));
            HTMLDocument.Close;
       end;


end;

{==============================================================================}

end.





Delphi Test Form

Unit1.dfm
{------------------------------------------------------------------------------------------------------------}


object Form1: TForm1
  Left = 233
  Top = 107
  Width = 870
  Height = 600
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object WebBrowser: TWebBrowser
    Left = 0
    Top = 0
    Width = 862
    Height = 573
    Align = alClient
    TabOrder = 0
    ControlData = {
      4C00000017590000393B00000000000000000000000000000000000000000000
      000000004C000000000000000000000001000000E0D057007335CF11AE690800
      2B2E126208000000000000004C0000000114020000000000C000000000000046
      8000000000000000000000000000000000000000000000000000000000000000
      00000000000000000100000000000000000000000000000000000000}
  end
  object IdHTTP1: TIdHTTP
    AllowCookies = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentLength = -1
    Request.Accept = 'text/html, */*'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = [hoForceEncodeParams]
    Left = 48
    Top = 28
  end
end 
Technical Details
Message-ID: <4886a35c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 123df9,434a5c700d17af24,start
X-Google-Attributes: gid123df9,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Mark Moss" <markmoss@ix.netcom.com>
From: "Mark Moss" <markmoss@adelphia.net>
Newsgroups: borland.public.delphi.com.activex.using
Subject: TWebBrowser
Date: Tue, 22 Jul 2008 21:19:46 -0600
Lines: 316
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.3959
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4133
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 75.71.50.160
Message-ID: <4886a35c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1216783196 75.71.50.160 (22 Jul 2008 20:19:56 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail