TWebInterface Documentation v2.0 (July, 3rd 98)

Description
___________

TWebInterface provides everything you need to build web application (or CGI). All the " hard " part is handled automatically and you can focus on application specific code, without to worry about CGI environment and constraints.

This component may be used in a standard Delphi application or in a console mode program. The former allows the component to be dropped on the main form, and the latter force the component to be created manually by calling the Create method (more on this below).

Component history
_________________

Development of TWebInterface component took place 18 monthes ago. I had to build a huge application running on the Internet and I needed some tools. Nothing was available then so I coded TWebInterface. It has evolved since then, to allow new features and to be more powerful. I decided to release it to public community (it may be of some help to somebody, somewhere, maybe ;) as a Freeware. All I ask, if you use it, is to send me an email at hitcher@geneva-link.ch. You will, however, not have the sources. But all compiled units are available and you should be able to use it without any problems. Complete sources are available for a modest fee of $25 (see Registration.Doc file for details).

Installation
____________

First, move all TWebInterface.* files and InetConstants.* to your Components directory. Start Delphi and open the menu Components/Install. Click the browse button, locate the file WebInterface.dcu (or WebInterface.pas for source code version) and click OK. Click OK again to rebuild your library. You will have a new tab on the component Palette, called " Hitcher " and an icon for the TWebInterface component will be available.

Methods
_______

Constructor Create(AOwner : TComponent)

  Create component instance and parse CGI parameters and form fields (if available).
  Procedure MyProc ;
  Var
    wiWeb : TWebInterface ;
  Begin
    wiWeb := TWebInterface.Create(nil) ;
    ...
  End ;

Destructor Destroy

  Destroy component instance and close output stream to remote browser.

Function GetDosVar(sEnvName : String) : String

  Returns DOS Environment variable value. Theses values are set by Microsoft IIS Web Server (like QUERY_STRING, cgi   parameters, or REMOTE_ADDR, remote IP address of client).

  Procedure MyProc ;
  Var
    sChaine : String ;
  Begin
    sChaine := wiWeb.GetDosVar('QUERY_STRING') ;
  End ;  

Function GetParamCount : Integer

  Returns actual number of parameters received on command line.

  Procedure MyProc ;
  Var
    iNumber : Integer ;
  Begin
    iNumber := wiWeb.GetParamCount ;
  End;

Function GetParamXName(iParam : Integer) : String

  Returns name of parameter # [iParam].

  Procedure MyProc ; 
  Var
    sName : String ;
  Begin
    sName := wiWeb.GetParamXName(0) ;
  End ;

Function GetParamXValue(iParam : Integer) : String

  Returns value of parameter # [iParam].

  Procedure MyProc ;
  Var
    sValue : String ;
  Begin
    sValue := wiWeb.GetParamXValue(0) ;
  End ;

Function GetParamValueByName(sParamName : String) : String

  Returns value of parameter named [sParamName].

  Procedure MyProc ;
  Var
    sValue := String ;
  Begin
    sValue := wiWeb.GetParamValueByName('WebCommand') ;
  End ;

Function GetFieldCount : Integer

  Returns actual number of fields received from a posted FORM.

Function GetFieldXName(iParam : Integer) : String 

  Returns name of field # [iParam].

Function GetFieldXValue(iParam : Integer) : String

  Returns value of field # [iParam].

Function GetFieldValueByName(sFieldName : String) : String

  Returns value of field named [sFieldName].

Procedure InitHTMLContext 

  Send initial dialog for HTML Document to remote browser, following RFC.

  Procedure MyProc ;
  Var
    wiWeb : TWebInterface ;
  Begin
    wiWeb := TWebInterface.Create(nil) ;
    With wiWeb Do Begin
      InitHTMLContext ;
      ...
    End ;
  End ;

Procedure InitJPGContext

  Send initial dialog for JPG Images to remote browser, following RFC.

Procedure InitGIFContext

  Send initial dialog for GIF Images to remote browser, following RFC.

Function ConvertPathToHTML(sPath : String) : String

  Convert usual UNC path to URL style (i.e. replace every '\' by '/') .

Function FillHTMLString(sHTML : String) : String

  Ensure that a string will be visible in browser. If the string is empty, it's replaced by HTML_Space, constant   defined by '&nbsp ;'. This is especially usefull when filling table's cells. If you send an empty string, the cell   won't be displayed, showing the background color. Simply call FillHTMLString before and all your cells will be   visible.

Function AnsiToHTML(sAnsiString : String) : String

  Convert a string from ANSI characters set to HTML RFC. Some characters are not allowed on web browsers and are   automatically converted before being sent. For example, the '+' sign is encoded to '%2B'. This function takes care   of that for you.

Function HTMLToAnsi(sHTMLString : String) : String

  Same thing as previous function but in the other side. You should call this function whenever you need to access a   form's field or a query string parameters, to ensure it is correctly encoded. If you have a <TEXTAREA> field on a   form, for example, and it has been filled with " Hello world ! ", you will initially receive " Hello+World+ ! ".   After calling HTMLToAnsi, this will be coded again to " Hello World ! ".

Procedure GenerateBreakLine(iNumber : Integer)

  Generate [iNumber] break line in your dynamic document. It simply write to remote client [iNumber] times the <BR>   tag.

Procedure SendLine(sLine : String)

  Write [sLine] to remote client

  Procedure MyProc ;
  Var
    wiWeb : TWebInterface ;
  Begin
    wiWeb := TWebInterface.Create(nil) ;
    With wiWeb Do Begin
      InitHTMLContext ;
      SendLine('Hello World') ;
      Free ;
    End ;
  End ;

Procedure Flush

  Flush output stream to remote client, forcing display of any pending text. Usefull while long internal operations   are in progress to show your visitor that something is in progress.

Procedure SendFile(sFileName : String)

  Send a complete file to remote browser, without any modifications.

  ...
  wiWeb.SendFile('c:\Documents\ThisFileIsForWeb.txt') ;
  ...

Procedure SendHeaders

  Send standard basic headers (<HTML> and <BODY> tags).

Procedure SendFooters

  Send standard basic footers (</BODY> and </HTML> tags).

Procedure SetTitle(sTitle : String)

  Set HTML document title (<TITLE>[sTitle]</TITLE> tags).

Procedure Refresh(iDelay : Integer ; sURL : String)

  Generate an META HTTP-EQUIV=Refresh tag that allow to redirect client to another page automatically after a   specified number of seconds. You may, for example, process a large amount of data, displaying status to remote   browser while work is in progress, and then redirect the client to another URL.

  Procedure MyProc ;
  Var
    wiWeb : TWebInterface ;
  Begin
    wiWeb := TWebInterface.Create(nil) ;
    With wiWeb Do Begin
      Refresh(15, 'http://www.geneva-link.ch') ;
      Free ;
    End ;
  End ;

Archive content
_______________

  In the archive, you should found the following files
    
    * /Bare/WebInterface.dcr
    * /Bare/WebInterface.bmp
    * /Bare/WebInterface.dcu
    * /Bare/InetConstants.dcu

Examples & Demos
________________

  Some demonstrations are available live on the Internet. Starting URL is   http://hitcher.infomaniak.ch/TWebInterface. You will find live versions of demos found in the TWebInterface   Component archive under directory " Demos ".

Contacting the author
_____________________

  You may reach me by email at hitcher@geneva-link.ch only. I usually check my mail several times a day, so don't   hesitate to post comments, bug reports, suggestions, etc...
