Delphi Internet Express: The Midas Server

By: Charles Calvert

Abstract: The Internet Express allows you to easily create XML based web server applications in Delphi.

Creating a Midas Server for the Internet Express

When building an Internet Express application you usually begin by creating a Midas server. The purpose of this section of the paper is describe how to create that simple Midas server..

NOTE: In many cases you will not be able to use unedited Delphi 4 servers with the Interent Express because the Midas protocol changed between Delphi 4 and 5. The change occurred so that Midas can serve up XML. So you may have to rebuild your Delphi 4 server, or else create a new server. When upgrading Midas servers to Delphi 5 first add the UpdateRegistry method from a Delphi 5 Midas server to your Delphi 4 Midas server, and replace your TProviders with Delphi 5 TDataSetProviders.

For the purposes of this article, we will, of course, create a new Midas server from scratch. The server you create will generate the XML data you send over the web. Remember, there are two parts to your Internet Express web server application:

  • One is the Midas server that talks to the database
  • The second is the web server application that takes output from the Midas server and sends it over the web.

When building these binary files it is often best to create at least three directories. One is your base directory which will host the other two directories. One of the subdirectories beneath your main directory is for your Midas server and one is for your InternetExpress webserver. There may be occasions when you will also want to create a standard Delphi Midas client or TWebConnection client, in which case you would create three or more directories beneath your main directory. The Midas client would be used to either test your Midas server, or to act as an alternative client.

As I specified in the previous paragraph, all of these directories should probably be under a single directory that acts as a wrapper for the whole project. The directory hierarchy should look something like this:

  • MyServer
    • MidasServer
    • WebServer
    • WebConnection
    • MidasClient

To build the Midas server, start a new application and save your work in the MidasServer directory. Select File | New and turn to the Multitier page. Add a Remote Data Module to your project. A remote data module is a regular Delphi data module that can export data not only to your current application, but also to remote applications.

When you run the Remote Data Module Wizard, it will prompt you for a name for your object. I usually call the data module after the most generic possible name for the data that I want to export. For instance, if I am building an Address server, then I would call it the AddressObject, while if I am building a server to access my music collection, I would call it the MusicObject. Alternatively, you could call it the AddressDataModule, or AddressRemoteDataModule.

The first example I show you will do nothing more than export the Country database from the DBDemos tables that ship with the product. As a result, you might want to call the object you create the CountryObject.

NOTE: I eschew Hungarian notation (rdmWhoAmI) because it is hard to read and forces alphabetical sorts to be by type, rather than by name. In other words, if your sort the variables in your objects, then end up sorted by type, and not be name. Usually that is not at all the effect your want to create. Nevertheless, Hungarian notation is a common technique, and I do not mean to imply that I think it is wrong. By all means, use Hungarian notation is you wish, my point is simply that it doesn't suit my tastes.

Once you have created your remote data module, you should save it to disk in the MidasServer directory. I always save my data modules under the name MainImpl.pas. This is just a convention that I adopt, so that when I look over my project, I know immediately where the data module is located. Any convention that you find meaningful will do just as well, but I would encourage you to develop some kind of convention.

Save the project itself under the name Country Server.

Now it is time to drop down a database server on the data module and hook up your tables. I will cover this process in the next section of the paper.

Setting up the Database on the Remote Data Module

The example webserver we are going to build will simply export the Country table from the DBDemos database that ships with Delphi. Here are the steps you need to take:

  1. First go to the Component Palette at the top of the Delphi IDE and select the Data Access page. Drop down a TTable on your remote data module. Hook the DatabaseName property of the TTable up to the DBDemos database, and select the Country table in the TableName property. Change the Name of the component to CountryTable.

  2. Drop down a TDataSetProvider and call it CountryProvider. Hook its DataSet property up to the CountryTable.

  3. Drop down a TSession component from the Data Access page of the Component Palette. Set its AutoSessionName to true.

When you are done your remote data module should look something like the screen shot shown in Figure 1.

The Remote DataModule for the Country Server

Figure 1: The Remote Data Module for the CountryServer.

Save your work. Compile the application, and run it once to register it. It is very important that you register your server with the OS. If you don't register it, the client won't be able to find it.

Server Response from: ETNASC04