Cross-platform DrBobCGI for Delphi, C++Builder, and Kylix

By: Bob Swart

Abstract: In this article I'll present the cross-platform edition of DrBobCGI 3.1 to help produce Web-server applications with Delphi, C++Builder, and Kylix without the need for the WebBroker technology. By Bob Swart.

In this Dr. Bob Examines article, I'll present the cross-platform edition of DrBobCGI version 3.1 (to help produce web-server applications with Delphi, C++Builder and Kylix without the need for the WebBroker technology).

Unit DrBobCGI automatically retrieves the environment variables (in Windows and Linux), then reads all input fields that were sent using the GET and the POST protocol as well as any Cookies. GET and POST field values can be used by calling a single function called "Value" which has the field name as argument, and the value as result. Cookie values can be obtained by calling the "CookieValue" function, which works similarly.

Apart from Value and CookieValue, DrBobCGI also automatically obtains the values for the HttpUserAgent (type and version of the browser), RemoteAddress (of the client), HTTP Authorization (base64 encoded), and the ScriptName (the name of the CGI application itself -- especially useful when producing single source cross-platform Windows and Linux web-server applications).

The public "usage" interface of DrBobCGI is defined as follows:

  unit DrBobCGI;
  {===================================================================}
  { DrBobCGI (c) 1999-2001 by Bob Swart (aka Dr.Bob - www.drbob42.com }
  { version 1.0 - obtain standard CGI variable values by "value()".   }
  { version 2.0 - obtain CGI values, cookies and IP/UserAgent values. }
  { version 2.1 - obtain Authorisation values (base64-encoded string) }
  { version 3.0 - ported to Kylix 1.0, still works with Delphi 4+ too }
  {               Note: DrBobCGI does not work with Delphi 3 or lower }
  { version 3.1 - combining GET and POST fields inside one Data field }
  {===================================================================}
  interface
  type
    TRequestMethod = (Unknown,Get,Post);
  var
    RequestMethod: TRequestMethod = Unknown;

  var
    ContentLength: Integer = 0;
    RemoteAddress: String[16] = ''; { IP }
    HttpUserAgent: String[128] = ''; { Browser, OS }
    Authorization: String[255] = ''; { Authorization }
    ScriptName: String[128] = ''; { scriptname URL }

    function Value(const Field: ShortString; Convert: Boolean = True): ShortString;
    function CookieValue(const Field: ShortString): ShortString;

As one of the examples in the article, I'll show how to set and get cookie values using DrBobCGI.

Unit DrBobCGI is free, with full source code supplied.

However, use at your own risk (it works for me), and feel free to send me feedback or any other comments. Thanks in advance!


Server Response from: ETNASC04