Internet Unplugged
Posted: (EET/GMT+2)
Internet Unplugged
May 20, 2000
Delphi 5 Professional & Enterprise
WAP, or Wireless Application Protocol has gained much popularity in the past months. Although it is related to mobile phones such as the Nokia 7110 or Ericsson R320, the content comes from the Internet. What you see on your WAP phone is read from special WML files that are addressed by regular URLs.
When you want to point your WAP phone to a WAP service, you simply type in a normal HTTP protocol link, like http://www.whirlwater.com/. But instead of assuming that the resulting data will be coded in HTML, your WAP phone assumes the data will be coded in WML, or Wireless Markup Language.
![]() |
It is not relevant to go into details of WML here. Instead, you should simply understand that a WML file contains the information that you can see on your WAP phone's screen. WML can be written with any text editor, for instance Notepad, and it could look like this: <?xml version="1.0"?> <!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> <wml> <card id="welcome" title="Welcome" newcontext="true" ontimer="#login"> <timer value="50"/> <p align="center"> <em>My First WAP</em><br/> <em>Service v1.0</em> </p> </card> </wml> |
If you look at the code closely, you can see that WML uses XML-style tags. Also, the document type definition for the WML format can be found from WAP Forum's web page at http://www.wapforum.org/. This is an address that you should definitely visit if you're interested in WAP applications.
Delphi goes wireless
Because WAP services can be pointed to by plain vanilla URLs, you could easily save your personal WML pages on a web server and access them using your WAP phone. Well, this is kind of neat, but far more interesting things become when you create dynamic solutions. For example, you could access you personal calendar no matter where you are!
If you are using Delphi 5 Professional or Enterprise, you could easily create a CGI or an ISAPI application to answer to your requests. The following text assumes you are familiar with Delphi 5's WebBroker technology, and if you are not sure about your skills, please consult your Delphi Developer's Guide. Beginning from page 29-1 you will find lots or information regarding web applications.
Without further ado, let's begin. Fire up Delphi, and choose the menu command File / New. This will open up the New Items dialog box. Select the Web Server Application icon, and click OK. Delphi will bring up the New Web Server Application Dialog box, with which you can choose the type of your web application. For the purposes of this article, choose to create an ISAPI/NSAPI application.
You should now see an empty web module in the IDE. A web module resembles a data module in that it is completely hidden at the run time. Right-click the Action word on the web module's left side (the tree view), and choose the Add item command from the popup menu. This will add a new action to the web module.
Implementing the action
Now that you have the action created, it is time to implement it as well. Click the action (named WebActionItem1) and make sure the property Default is set to True (make this change using the Object Inspector). Next, go to the Events page of the Object Inspector, and double-click the OnAction event to bring up the code editor. As for the event handler, type in the following code:
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.ContentType := 'text/vnd.wap.wml';
Response.Content := '<?xml version="1.0"?>'#13#10+
'<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" '+
'"http://www.wapforum.org/DTD/wml_1.1.xml">'#13#10+
'<wml>'#13#10+
''#13#10+
'<card id="welcome" title="Welcome" newcontext="true">'#13#10+
' <p align="center">'#13#10+
' <em>My First WAP</em><br/>'#13#10+
' <em>Service v1.0</em>'#13#10+
' </p>'#13#10+
'</card>'#13#10+
''#13#10+
'</wml>'#13#10;
end;
Once you have typed in the code, save and compile the project. Copy the resulting DLL file to your web server's scripts directory, for example C:\InetPub\Scripts if you are using Microsoft Internet Information Server (IIS). After you have completed these steps, you are ready to run the project.
Testing your application
To test your ISAPI WAP application, you need to have either a WAP phone or a WAP phone simulator. The easiest way to test your WAP application is to get Nokia's WAP Toolkit (see the next picture) from Nokia's WAP developer web site. This toolkit is free after a registration procedure.

At the time of this writing, the newest version of the WAP toolkit supports WML 1.1. This is fine for the sample application represented in this article, but later versions of the simulator should also be able to support WML 1.2. Anyway, download the simulator and fire it up.
The simulator has a Go menu, from which you should choose the Load Location command. A simple dialog box opens, allowing you to type in an URL. Type in an URL like this: http://localhost/scripts/simplewap.dll. If your web server's scripts directory is named differently or you saved your WAP application project under a different name, adjust the URL accordingly.
Once you click OK, the WAP toolkit starts to query your web server. If everything goes smoothly, you web server will soon execute your application, producing a text "My First WAP Service v1.0" text on the screen of the virtual mobile phone.
The sample application developed here is about the simplest dynamic WAP application you can possibly create. Of course, it should go without saying that you are free to do whatever you want in the OnAction event handler. For example, you could easily access databases, and format appropriate WML code to display the data.
Download the example code
Download internetunplugged.zip (175 kB) which contains the sample application "SimpleWAP". Please note that the sample application will require Delphi 5 Professional or Enterprise.
* * *
Need help developing your WAP project? Contact us!
