Methods 2

Navigate(by by Vino Rodrigues from
Borland): To display a Web page or document in the TEmbeddedWB component, wen need use the Navigate method programmatically. The syntax for the Navigate method is: procedure Navigate(const URL: WideString); overload; procedure Navigate(const URL: WideString; var Flags: OleVariant); overload; procedure Navigate(const URL: WideString; var Flags: OleVariant; var TargetFrameName: OleVariant); overload; procedure Navigate(const URL: WideString; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant); overload; procedure Navigate(const URL: WideString; var Flags: OleVariant; var TargetFrameName: OleVariant; var PostData: OleVariant; var Headers: OleVariant); overload;

Where:

• URL specifies the UNC path name of a file or the Uniform Resource Locator (URL) of an Internet resource that the Web browser should display.

If URL refers to an Internet protocol and a location on the Internet, your application must establish a connection before is can display the document. If the computer running your application is connected to a proxy server (a secure connection to the Internet through a LAN), or if it has a direct connection to the Internet, the TEmbeddedWB component downloads and displays the Web page or other Internet content immediately. If the computer running your application uses a modem and dial-up connection to the Internet, and that connection hasn't been established beforehand, the TEmbeddedWB component initiates the connection.

If URL refers to an Internet protocol and a location on an intranet server, the computer running your application must be connected to the intranet and have permission to access that server.

If URL refers to a standard file system path on a local hard drive or intranet, the TEmbeddedWB component opens the document and displays it immediately. The TEmbeddedWB component can open Microsoft Office documents, text files, and HTML documents that don't require features supported only by an Internet server. For example, the TEmbeddedWB component can't open HTML documents that use IDC/HTX files or Active Server Pages (ASP) files from the standard file system, but it can open HTML documents that contain only the HTML tags supported by Microsoft Internet Explorer.

Note: If URL refers to a path in the standard file system that doesn't refer to a file name (for example, C:WindowsSystem), the TEmbeddedWB component displays the file system itself, much like My Computer.

• Flags is a set of values that specify whether to add the resource to the history list, whether to read from or write to the cache, and whether to display the resource in a new window. It can be a sum of zero or more of the following:

 Constant Value Meaning NavOpenInNewWindow $01 Open the resource or file in a new window. NavNoHistory$02 Do not add the resource or file to the history list. The new page replaces the current page in the list. NavNoReadFromCache $04 Do not read from the disk cache for this navigation. NavNoWriteToCache$08 Do not write the results of this navigation to the disk cache. NavAllowAutosearch \$10 If the navigation fails, the Web browser attempts to navigate common root domains (.com, .org, and so on). If this still fails, the URL is passed to a search engine.

• TargetFrameName is the name of the frame in which the resource will be displayed, or nil if the resource should not be displayed in a named frame.

• PostData contains the data sent to the server when using Navigate to generate an HTTP POST message. If PostData is nil, Navigate generates an HTTP GET message. PostData is ignored if URL does not specify an HTTP URL.

• Headers contains any headers sent to the servers when the URL represents an HTTP URL. HTTP headers specify such things as the intended action required of the server, the type of data, and so on.

procedure TForm1.Button1Click(Sender: TObject);
var // Autor: Thomas Stutz

Url, Ref: string;
IEApp: OLEVariant;
begin

Flags := '1';
TargetFrameName := '';
PostData := '';
Url := 'http://www.dach.de/weiterempfehlen.php';
Ref := 'http://www.dach.de/';

// u cannot navigate to the url above without this referer

Headers := 'Referer: ' + Ref + #10 + #13;
end;

Navigate2: Use Navigate2 to locate and download a specific resource. Navigate can send an HTTP message to a specified URL and display the results, display the results of a specified file, or navigate to a resource that can't be expressed as an URL such as an item identifier list. URL specifies the UNC path name of a file, the Uniform Resource Locator of an Internet resource, or a pointer to an item identifier list (PIDL). Flags is a set of values that specify whether to add the resource to the history list, whether to read from or write to the cache, and whether to display the resource in a new window. It can be a sum of zero or more of the following:

Constant

TargetFrameName is the name of the frame in which the resource will be displayed, or NULL if the resource should not be displayed in a named frame. PostData contains the data sent to the server when using Navigate to generate an HTTP POST message. If PostData is NULL, Navigate generates an HTTP GET message. PostData is ignored if URL does not specify an HTTP URL. Headers contains any headers sent to the servers when the URL represents an HTTP URL. HTTP headers specify such things as the intended action required of the server, the type of data, and so on. (See TWebRequest object, whose properties represent many of the more common headers).

A nice example by
HHF Innovations:
Q: How can I pass PostData when I Navigate to a URL?

A: I call the below method with a URL destination, PostData in the format of 'animal=cat&color=brown' etc. and the TEmbeddedWB object that I want to load the URL inside of...

procedure TDBModule.Navigate(stURL, stPostData: String; var wbEmbeddedWB: TEmbeddedWB);var  vWebAddr, vPostData, vFlags, vFrame, vHeaders: OleVariant;  iLoop: Integer;begin  {Are we posting data to this Url?}  if Length(stPostData)> 0 then  begin    {Require this header information if there is stPostData.}    vHeaders:= 'Content-Type: application/x-www-form-urlencoded'+ #10#13#0;    {Set the variant type for the vPostData.}    vPostData:= VarArrayCreate([0, Length(stPostData)], varByte);    for iLoop := 0 to Length(stPostData)- 1 do    // Iterate    begin      vPostData[iLoop]:= Ord(stPostData[iLoop+ 1]);    end;    // for    {Final terminating Character.}    vPostData[Length(stPostData)]:= 0;    {Set the type of Variant, cast}    TVarData(vPostData).vType:= varArray;  end;  {And the other stuff.}  vWebAddr:= stURL;  {Make the call Rex.}  wbEmbeddedWB.Navigate2(vWebAddr, vFlags, vFrame, vPostData, vHeaders);end;  {End of Navigate procedure.}

This tip provided by Craig Foley based on techniques from Nathan Wilhelmi's Usenet posting to borland.public.delphi.internet on the 31/1/99

A: Here's another option:

procedure TForm1.SubmitPostForm;var  strPostData: string;  Data: Pointer;  URL, Flags, TargetFrameName, PostData, Headers: OleVariant;begin  {  <!-- submit this html form: -->  <form method="post" action="http://127.0.0.1/cgi-bin/register.pl">  <input type="text" name="FIRSTNAME" value="Hans">  <input type="text" name="LASTNAME" value="Gulo">  <input type="text" name="NOTE" value="thats it">  <input type="submit">  </form>  }  strPostData := 'FIRSTNAME=Hans&LASTNAME=Gulo&NOTE=thats+it';  PostData :=  VarArrayCreate([0, Length(strPostData) - 1], varByte);  Data := VarArrayLock(PostData);  try    Move(strPostData[1], Data^, Length(strPostData));  finally    VarArrayUnlock(PostData);  end;  URL := 'http://127.0.0.1/cgi-bin/register.pl';  Flags := EmptyParam;  TargetFrameName := EmptyParam;  Headers := EmptyParam; // TEmbeddedWB will see that we are providing                         // post data and then should automatically fill                         // this Headers with appropriate value  EmbeddedWB1.Navigate2(URL, Flags, TargetFrameName, PostData, Headers);end;

This tip provided by Hans Gulo.

Procedure NavigateFolder(CSIDL: Integer);

browsing on special folders—such as Desktop and My Computer:

Procedure NavigatePidl(pidl : PItemIdList);
 EmbeddedWb1.NavigateFolder(CSIDL_Desktop);

Quit: Do not use this method. It is included in the TEmbeddedWB interface because the IEmbeddedWB2 interface is shared with Internet Explorer. Internet Explorer responds to Quit by shutting down

Refresh: (By Borland) Call Refresh to reload the current document. This is useful when the Web browser is displaying the resource at an URL that may have changed. Refresh always sends a pragma:nocache header, telling the server not to return a cached copy. This can cause problems with some servers. To prevent the pragma:nocache header, or to refresh only expired pages, use the Refresh2 method instead.

Refresh2: (By Borland) Call Refresh2 to reload the current document. Unlike the Refresh method, Refresh2 lets you specify what level of refresh to perform. Level indicates what type of information is refreshed. The following table lists the possible values:

Constant

When Level is omitted, a value of REFRESH_COMPLETELY is assumed.

Syntax

Procedure SetFocusToDoc;

This procedure is added to make it possible to TAB the way to the content of the EmbeddedWB . It is also useful for functions, that need to have the focus set on the document in EmbeddedWB (ex. see OnShowHelp).

function HtmlHelp;

API call to make it easy to implement Help-file in the EmbeddedWB application. (see OnShowHelp).

function AssignDocument;

Opens a blank page in EmbeddedWB-control if document is unassigned. Used in LoadFromStrings and LoadFromStream.

function LoadFromStrings(aStrings : TStrings) : HRESULT;

Display content of aStream in EmbeddedWB.

function LoadFromStream(aStream : TStream) : HRESULT;

Display content of aStrings in EmbeddedWB.

 procedure TForm1.Button1Click(Sender: TObject); var T : TMemoryStream; begin   T := TMemoryStream.Create;   try     T.LoadFromFile('C:\temp\test.htm');     EmbeddedWb1.LoadFromStream(T);   finally   T.Free;   end; end;

function SaveToFile(const Fname : String) : HRESULT;

Save HTML-source from EmbeddedWB.Document to file Fname.

 procedure TForm1.Button2Click(Sender: TObject); begin EmbeddedWb1.Go('http://www.microsoft.com'); EmbeddedWb1.SaveToFile('c:\microsoft.htm'); end;

function SaveToStrings(aStrings : TStrings) : HRESULT;

Save EmbeddedWb.document to stringlist.

 procedure TForm1.Button1Click(Sender: TObject); begin EmbeddedWb1.Go('http://www.microsoft.com'); EmbeddedWb1.SaveToStrings(memo1.lines); end;

function SaveToStream(aStream : TStream) : HRESULT;

Save EmbeddedWB.document to a stream. The following sample loads a webpage in the browser. When download is completed the HTML-source is displayed in Memo1 and saved to a file, using a TMemoryStream:

 procedure TForm1.Button3Click(Sender: TObject); var   M : TMemoryStream; begin   M:=TMemoryStream.Create;   EmbeddedWb1.Go('http://www.microsoft.com');   EmbeddedWb1.SaveToStream(M);   M.Seek(0,0);   Memo1.Lines.AddFromStream(M);   M.SavetoFile('c:\microsoft.htm');   M.Free; end;

function RegisterNameSpace(clsid : TGUID) : HRESULT;

Register the temporary namespacehandler clsid. There seems to be a unconfirmed bug in IInternetProtocol.RegisterNameSpace, so namespace-patterns cannot be added. Instead you can add your namespace in function "Start" in your namespacehandler-object:

ShowBrowserBar: Do not use this method. It is included in the TWebBrowser interface because the IWebBrowser2 interface is shared with Internet Explorer. Internet Explorer uses ShowBrowserBar to show or hide a specified browser bar.

Stop: Stop cancels any pending navigation or download operation and terminates any dynamic page elements, such as background sounds and animations.
Do not expect that stop will work at once like magic. It depends on several IE dll's so be patient.

function TMyNSHandler.Start(szUrl: PWideChar; OIProtSink: IInternetProtocolSink; OIBindInfo: IInternetBindInfo; grfPI, dwReserved: DWORD): HResult;
begin
if
Pos('http://' + <NameSpace> + '/', LowerCase(szUrl)) <> 1
then Result := INET_E_USE_DEFAULT_PROTOCOLHANDLER
else begin
...
end;

SetGlobalOffline

Use SetGlobalOffline to switch between 'Work Online' and 'Work Offline'.

SetGlobalOffline(TRUE) = Work Offline;

SetglobalOffline(FALSE)= Work Online;

Use IsGlobalOffline to detect if your EmbeddedWB is in global offline mode. The following lines of code adds a menu item for switching between 'Work Offline' and 'Work Online':

 procedure TForm1.Offline1Click(Sender: TObject); var State : Boolean; begin state:=IsGlobalOffline; EmbeddedWb1.SetGlobalOffline(not State); If State then Offline1.Caption:='Work Offline' else  Offline1.Caption:='Work Online'; end;

SetGlobalOffline works exactly as 'Work Offline/Online'  in IE4/IE5.

Offline BrowsingThis function is based on source-code posted by Adam Stiles in the delphi-EmbeddedWB newsgroup (Message 426).

function UnregisterNameSpace : HRESULT;

Unregister a temporary pluggable namespacehandler.

function RegisterMIMEFilter(clsid: TGUID; MIME : PWideChar) : HRESULT;

Register the temporary pluggable MIME filter clsid to be used for MIME-type MIME.

function UnregisterMIMEFilter(MIME : PWideChar) : HRESULT;

Unregister the a temporary pluggable MIME filter for MIME-type MIME.

Zoom: The following lines of code are all you need to add a textsize menu to your application, similar to the one in Internet Explorer.

Create 5 Menuitems: Smallest, Small, Medium, Larger, Largest.
Set Medium.Checked to True;
Set the Tag-value for the Menuitems from 0 (smallest) to 4 (largest).
Connect the 5 OnClick-events to the same function:

 procedure TForm1.Smallest1Click(Sender: TObject); begin  Smallest1.Checked:=False;  Small1.Checked:=False;  Medium1.Checked:=False;  Larger1.Checked:=False;  largest1.checked:=False;  EmbeddedWb1.Zoom((Sender as TMenuitem).Tag);  (Sender as Tmenuitem).checked:=True; end;

Last modification：August 16th, 2009 at 12:30 pm