Customizing

Adding Your Own Protocols

The Connection concept makes it easy to add or modify protocols. A few possible reasons that you might want to do this are:

- To read HTML from encrypted files
- To read HTML from a database.
- To use a different http component.

The various connection types are defined in `URLConId.pas`. To add a new protocol, it's necessary to define a descendent to `TURLConnection`, the base class. In most cases, this is a two step process:

1. Add your new protocol string to `TURLConnection.GetConnection`. This makes your new connection available for use.
2. Override the `TURLConnection.Get` method. The code you add here should use the URL to determine what stream to return. It's also necessary to specify the content type (HTMLtype, TEXTtype, or ImgType) of the return.

URL Format Considerations

TFrameBrowser has the capability of assembling full URLs from partial URLs. The syntax for doing this is detemined by the standard http and file protocols. This means that any special protocols that are added should use URLs that resemble those used by the http and file protocols.

The general form of a special URL should be:

         proto://dir1/dir2/file.ext
      or
         proto:///file.ext

The important points are:

- The protocol string should be followed by a colon and two (possibly three) forward slashes.
- dir1/dir2/ represent a directory or other hierarchy. The user can determine how this should be interpreted in his `Get` method code.
- Whatever follows the last forward slash is taken as a document or image name
- The URL should contain at least three forward slashes. If there are only two, one will be added on the end.

Adding HTML documents to an Application's Resources

To construct a resource file containing HTML documents and images suitable for the res protocol, proceed as follows:

- Write a resource compiler file (.rc) listing the files to be included.
- Use the Borland Resource Compiler to compile the .rc file into a .res file. The Borland Resource Compiler is named BRCC32 (32 bit) or BRCC (16 bit).
- Reference the .res file in your program code using the {$R } compiler directive.

A typical resource compiler file might look like:

      //   usage:  BRCC32.EXE -foHelp32.res proghelp.rc

      		agif2       GIF   "agif2.gif"
      		readme3     HTML  "readme3.htm"
      		readme1     HTML  "readme1.htm"
      		readme2     HTML  "readme2.htm"
      		leftwin     HTML  "leftwin.htm"
      		index       HTML  "help.htm"
      		style       HTML  "style.css"
      		borders	    TEXT  "borders.txt"

The first column is the name by which the resource is referenced. Column two is the resource type. The res protocol as defined recognizes HTML, HTM, GIF, JPG, JPEG, BMP, PNG, and TEXT types. The third column is the file which defined the HTML document.

In the above, the URL, `res:///index.htm`, would load the resource defined by the file, `help.htm`.