Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Dr.Bob's Delphi Notes Dr.Bob's Delphi Clinics Dr.Bob's Delphi Courseware Manuals
 Dr.Bob Examines... #80
See Also: other Dr.Bob Examines columns or Delphi articles

Delphi 2006 and Apache Web Apps
Unleashing the hidden Apache support in (Turbo) Delphi 2006 again

This article applies to anyone moving from Delphi 7 to (Turbo) Delphi 2006 for Win32. Apart from the fact that the new IDE requires the .NET Framework to be installed (even if the resulting applications are 100% pure Win32 applications that don't need the .NET Framework at all), there are some more changes made to Delphi 2006 compared to Delphi 7. One of them is the lack of support for CLX and Linux related code. The other is the lack of support for Apache web applications. Delphi 2005 and 2006 are no longer able to generate new Apache 1.x or 2.x web applications.
Or are they? In this article, I'll show you a back door to the rabbit hole, which still exists... for now...

New Web Server Application
When it comes to web applications, Delphi 7 supports ISAPI/NSAPI, CGI, Apache 1.x, Apache 2.x as well as a Web App Debugger target (which should only be used for debugging and not deployment). Compared to Delphi 6, the WinCGI target is missing, but the Apache 2.x target is added. Below you can see the Delphi 7's New Web Server Application wizard:

Delphi 7's New Web Server Application Wizard

Note that a similar set of web application target choices can be made in the New WebSnap Application wizard as well as the New SOAP Server Application wizard. And although the later doesn't show the "Cross-Platform" checkbox, the resulting CGI and Apache SOAP Server web application can still be made cross-platform by making sure the web module .dfm file gets the .xfm file extension.
Note by the way that Delphi 7's support for Apache 2.x is in fact support for Apache 2.0.39. Unfortunately, by the time Delphi 7 was available, Apache version 2.0.40 was available, which was not compatible with 2.0.39 due to some interface changes. For more information about these changes, covering Apache 2.0.40 up until the latest version of Apache 2.0.59, see http://www.drbob42.com/Delphi7/Apache2040.htm. Note that the latest versions of Apache in the 2.2.x range are not supported.

Delphi 2005 & 2006
Since Delphi 2005 and Delphi 2006 no longer support or contain CLX, it's no wonder that the "Cross Platform" checkbox is gone. However, it you compare the New Web Server Application wizard from Delphi 2006 (as seen below) to the one from Delphi 7 (see above), then you will notice even more differences.

Delphi 2006's New Web Server Application Wizard

It appears that Delphi 2005 and Delphi 2006 are no longer able to generate new Apache 1.x or Apache 2.x web server applications!

Existing Apache Web Applications
Is Apache support completely removed from Delphi 2005 and 2006? What about existing Apache web application projects?
It turns out that these can still be compiled with Delphi 2005 and 2006. The Apache specific units ApacheApp and ApacheTwoApp are still included, and so are the other Apache specific units HTTPD and ApacheHTTP (for Apache 1.x) and HTTP2D and ApacheTwoHTTP (for Apache 2.x) are included with the recent versions of Delphi. In fact, it appears that the HTTP2D.pas unit which is included with Delphi 2005 has been modified to support Apache 2.0.42, according to the instructions from the URL on my website. I guess Apache 2.0.42 was the current version just before Delphi 2005 shipped. Too bad the HTTP2D.pas unit was not updated again when Delphi 2006 shipped, since it's still at Apache 2.0.42 support. Fortunately, if you need support for anything between 2.0.42 and 2.0.59, my Delphi Apache 2.x page will still help.
The only thing that doesn't work in Delphi 2005 and 2006 is opening the designer for a unit with an .xfm form file (instead of the .dfm form file). Fortunately, this can be fixed by renaming the .xfm files to .dfm and fixing the {$R *.xfm} to {$R *.dfm} in the corresponding .pas unit. You need to reopen the project to allow the designer to recognise the .dfm file again.

New Apache Web Application
If existing Apache 1.x and 2.x web server applications still compile with Delphi 2005 and 2006, then why is Delphi unable to generate new Apache web server applications?
I guess the answer is that Apache support in Delphi 2005 and 2006 is now what Borland calls "deprecated". Meaning the support to compile existing applications is still in the product, but it's no longer officially supported, and may be removed in a future version of Delphi.
OK, I can live with that. But in the meantime, it's still available in the box. And since Apache 2.x support was not available in Delphi 6, but only added in Delphi 7, it would appear that only people with a copy of Delphi 7 are able to produce new Apache 2.x web server applications (that can be compiled with Delphi 7, 2005 as well as 2006). Since there may be Delphi 2005 or 2006 developers out there who don't own Delphi 7, I will now explain how to produce new Apache applications from Delphi 2006 (or 2005).

Delphi 2006 and Apache
As first step, just create a New Web Server Application, either WebBroker, WebSnap or a Web Service, and select the ISAPI/NSAPI Dynamic Link Library as target. We will then modify the main project file and turn it into a target for Apache 1.x or Apache 2.x.
The original source code for the ISAPI/NSAPI web application, will look as follows:

  library Project1;

  uses
    ActiveX,
    ComObj,
    WebBroker,
    ISAPIApp,
    ISAPIThreadPool,
    Unit1 in 'Unit1.pas' {WebModule1: TWebModule};

  {$R *.res}

  exports
    GetExtensionVersion,
    HttpExtensionProc,
    TerminateExtension;

  begin
    CoInitFlags := COINIT_MULTITHREADED;
    Application.Initialize;
    Application.CreateForm(TWebModule2, WebModule2);
    Application.Run;
  end.
Where Project1 and Unit1 can have a different name, depending on how many ProjectX and UnitX files are already on your machine.
First of all, change the uses clause and remove the ActiveX, and ComObj, lines, and replace the ISAPIApp and ISAPIThreadPool with the ApacheApp unit (for Apache 1.x) or the ApacheTwoApp unit (for Apache 2.x).
Next, remove the three lines from the exports section, and replace them by only one, as follows:
  exports
    apache_module name 'Project1_module';
Where Project1 is the name of the library itself (so you need to modify this if your library has another name of course).
Finally, you need to remove the CoInitFlags statement in the begin-end block, which is also ISAPI specific.
The result is an Apache web server application project, which might look as follows:
  library Project1;
  uses
    WebBroker,
    ApacheTwoApp,
    Unit1 in 'Unit1.pas' {WebModule2: TWebModule};

  {$R *.res}

  exports
    apache_module name 'Project1_module';

  begin
    Application.Initialize;
    Application.CreateForm(TWebModule2, WebModule2);
    Application.Run;
  end.
This project will compile to an Apache 2.x web server application, and can now be edited using Delphi 2005 or 2006 and turned into the WebBroker, WebSnap or Web Service application you wanted to build.

Summary
It may take a few modifications, but in less time than you can say "Slartibartfast" (ten times), you can create your own new Apache web server applications with Delphi 2005 or 2006, even when they are officially no longer supported. Of course, when the next version of Delphi ships, the Apache support may be completely gone from the product, but for the time being, it's there to be used.
Note that since Turbo Delphi for Win32 and Turbo C++ are based on the Professional version of BDS 2006, it's very likely that they will also include the (hidden) Apache support. We'll know on September 5th.


This webpage © 2006-2010 by Bob Swart (aka Dr.Bob - www.drbob42.com). All Rights Reserved.