Friday, March 20, 1998 Hanover Germany
C++ Programmers - Two Faces, One Language
Building a Web Server Application
I am at the annual CeBit computer show in Hanover Germany. This show lasts for seven
days and has over 850,000 attendees (and I thought Comdex Las Vegas was big). I am on
another one of my 10 countries in 10 days trips to Europe showing C++Builder 3 and
previewing JBuilder 2 to customers, press and partners. In my visits with developers
I have been impressed with the quality of the projects they are working on and the
questions they ask. One example in Italy is a multi-tier Delphi/Interbase/As400 application for
a major clothing manufacturer. The application lets employees in the store order clothes direct
from the factory when stocks are low.
As I travel I am often asked if developers are different around the world. I am also asked
where the best developers are. My answer to both questions are that there are great
developers everywhere. No country has a lock on the best programmers. We all have access
to the best tools, the latest information, and the future operation system and hardware
interfaces. Programmers around the world are trying to solve the same business problems.
To get a finger on the pulse of C++ developers, last fall we placed a survey on
Borland Online (there is a survey now available for Delphi
programmers too). The survey asked what types of applications
were they building, what problems were they facing, and what were their future
application development requirements. From the survey two distinct types
of C++ programmers and their needs emerged - Systems Developers
and Applications Developers.
C++ Developer Web Survey Results
More than 8,000 C++ developers responded to the survey. The survey showed that
they are unhappy with the current tools they are using especially in the areas
of creating visual applications, debugging, and project management.
Their future requirements include the ability to easily create database, Internet,
and visual applications all within the same environment. C++ developers told us
that they did not want to have to use one visual tool for the user interface, and
another tool for database and systems programming.
They also told us that the critical issues facing every C++ developer are
programmer productivity, application performance, and support for industry standards.
Developers were also asked what type of applications they were building,
what were the application characteristics, what debugging support
they required, and the type of project build environment they needed.
C++ Systems Programmers
Systems programmers focus on performance generally building console applications,
NT Services, device drivers, ActiveX controls, embedded and real-time systems.
The applications they build are usually characterized as being non-visual,
high-performance, low-level, object oriented, and built with object frameworks.
The debugging support required includes a native code generated assembly language
view, complex conditional breakpoints, and ability to view application events.
Their build/make project environment needs to be very modular and flexible, and
has to support the building of many targets. The bottom line for C++ Systems Programmers
is an ANSI/ISO C++ compiler, strong debugging, and support for system API's and
object frameworks.
C++ Application Programmers
Application programmers focus on productivity using C++ to build database, Internet,
multi-tier, and game applications. Their applications are characterized by
being very visual, high-performance, component oriented, and event driven.
Debugging of applications requires local variable inspection, conditional
breakpoints, and the ability to step into, out of, and over functions. Their
project management environment needs to support building of forms, DLLs,
resources, and multiple targets. The bottom line for C++ Application
Programmers is support for database programming, Internet standards and
assembling applications using components.
Solution: C++Builder 3!
Borland C++Builder 3 is the solution for both the systems developer
and the application developer. It delivers the productivity and
performance that you expect and demand when building any Windows
applications. C++Builder 3 delivers the advanced Project Manager
for handling complex applications requiring multiple target types,
six new powerful debugging capabilities, over 15 new compiler
options for smaller and more efficient code, seamless client/server
database development and three new integrated internet development
technologies. Exclusive to C++Builder 3 are technology solutions
for decision support with the Decision Cube multi-dimensional
cross-tab components, MIDAS (Multi-Tier distributed application
services) development kit for building business critical
applications with DCOM, and the new Adaptive Compiler
Technologies for unbelievable performance.
Building a C++Builder3 Web Server Application - A Different Type of Survey
Which category of C++ programmer are you? Systems or Applications programmer? In a
smaller development department you might be both. Are there other critical factors
that affect your development efforts? I have included my own short survey
below to find out more about C++ programmer issues. If you are interested in taking
part in the David I survey, click here.
With C++Builder3 Client/Server Suite you can build your own web server applications. C++Builder3 includes
new components (WebModule, PageProducer, QueryTableProducer, and DataSetTableProducer) that
let C++ programmers build CGI (Common Gateway Interface), WinCGI (Windows CGI), ISAPI (Microsoft Internet Information
Web Server API), and NSAPI(Netscape Web Server API) web server applications. The WebBroker technology included
with C++Builder3 Client/Server Suite lets you build one set of web server application logic and use
it to build all four types of server applications. In my case
I've built an ISAPI DLL web server application that creates a HTML survey form and uses InterBase to store
the responses. The source code for the survey is included in a zip file.
Steps to Build the Web Survey ISAPI DLL Server Application
This section lists the steps required to build and test the web server DLL. To test the DLL you will need either the Microsoft Internet
Information server running under Windows NT, or the Microsoft Personal Web server running under Windows 95. If you
decide to build a CGI or WinCGI executable you can also use the O'Reilley & Associates Web Server as well.
You can build web server applications either as CGI/WinCGI executables (.exe) or ISAPI/NSAPI DLLs (.dll) files.
Executables are loaded as separate processes and are automatically unloaded from memory when the web request is finished.
To debug a web server executables you use the old fashion text file output method, dumping messages and values to
an external file. DLLs are loaded into the same process space as the web server and stay in memory for all subsequent
requests. With C++Builder3's new DLL debugging capabilities you can easily use the development environment to step
through your logic. One downside with using web DLLs is that you have to stop your web server to kick the
DLL out of memory so that you can copy newer versions of the DLL into your web applications folder.
Step 1 - Build the InterBase database
Build an InterBase database to hold the survey results.
The meta data for the database is very simple.
CREATE DATABASE "C:Survey.gdb" PAGE_SIZE 1024;
CREATE TABLE SURVEY (SURVEYKEY INTEGER NOT NULL,
SURVEYNAME VARCHAR(20) NOT NULL,
QUESTIONNUMBER INTEGER NOT NULL,
QUESTIONKEYWORD VARCHAR(20) NOT NULL,
USERANSWER VARCHAR(40),
PRIMARY KEY (SURVEYKEY));
CREATE GENERATOR SURVEY_GEN;
CREATE TRIGGER CREATE_SURVEYKEY FOR SURVEY
ACTIVE BEFORE INSERT POSITION 0
AS BEGIN
NEW.SURVEYKEY = GEN_ID(SURVEY_GEN, 1);
END;
Step 2 - Create the BDE Alias
The alias name for the InterBase database needs to be SURVEY. Set the database
type to InterBase. Set the directory path to where you put your Survey.gdb file.
Step 3 - Start C++Builder3 and Create a Web Server Application
Start up C++Builder 3. From the main menu chose File|New. Select the
Web Server Application from the object repository. This will bring up the Web Server Application wizard.
Chose the radio button for ISAPI/NSAPI to create the DLL project and the main application source file
and the Web Module. You can also chose to build a CGI or WinCGI application.
Step 4 - Add a Database component to the Web Module
From the Data Access component palette drop a Database component into the Web Module. This will allow you to connect
to the InterBase database, login to the database and stay connected between sessions. Set the Name property to SurveyDatabase. Set the
AliasName property to the Survey alias created in Step 2. Set the DatabaseName property to any text string. Set the Params property
to the folling strings:
USER NAME=SYSDBA
PASSWORD=masterkey
Set the LoginPrompt property to false (the Params property will contain the needed username and password). Set the HandleShared
property to True. Set the Connected property to true to turn on the connection to the InterBase database.
Step 5 - Add a Table component to the Web Module
From the Data Access component palette drop a Table component into the Web Module. Set the Name property to SurveyTable.
Set the DatabaseName property to the string you set in the Database component. Set the TableName property
to the SURVEY table in the InterBase database. Set the Active property to True.
Step 6 - Add a PageProducer component to the Web Module
The first page producer will be used to generate the survey questions HTML page. Set the Name property to SurveyPageProducer. Set the HTMLFile property to the Survey.HTM html file included in the source code zip file. You could also
use the HTMLDoc property to embed the HTML strings into the executable. There are two notes included
in the C++Builder3 help file that are important when using the PageProducer.
- Note: Setting HTMLFile clears the HTMLDoc property.
- Note: When distributing applications that contain page producers which use the HTMLFile property, be sure to distribute the file along with the application.
Also, be sure that the value of HTMLFile does not include a hard-coded path name that will not be available on the users disk.
I placed the Survey.HTM file in the same directory as my web server application DLL.
The HTMLFile text is too long to list in this column so I will just show you the HTML
file with one of the survey questions.
<HTML>
<HEAD>
<TITLE>David I's Survey January 1998</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#006666"
ALINK="#009999" VLINK="#666666">
<h2>David I's January 1998 Survey</h2>
<form method=POST action="/scripts/websurvy.dll/survey">
<h3>1) What do you eat while you are programming?</h3>
<UL>
<table cellpadding="2" cellspacing="2">
<td><INPUT TYPE="radio" NAME="food" VALUE="Pizza">Pizza</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Sushi">Sushi</td>
<tr>
<td><INPUT TYPE="radio" NAME="food" VALUE="Pasta">Pasta</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Cookies">Cookies</td>
<tr>
<td><INPUT TYPE="radio" NAME="food" VALUE="Chips and
Salsa">Chips and Salsa</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Candy">Candy</td>
<tr>
<td><INPUT TYPE="radio" NAME="food" VALUE="Popcorn">Popcorn</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Trail Mix">Trail Mix</td>
<tr>
<td><INPUT TYPE="radio" NAME="food" VALUE="Burgers and
Fries">Burger and Fries</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Chinese">Chinese</td>
<tr>
<td><INPUT TYPE="radio" NAME="food" VALUE="Crackers and
Cheese">Crackers and Cheese</td>
<td><INPUT TYPE="radio" NAME="food" VALUE="Programming is food"
CHECKED>Programming is the food of life</td>
</table>
</UL>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Reset">
</form>
</body>
</html>
You'll find the complete HTML I used in the source code zip file both
in the Web Module form file and in a separate survey.txt file.
Step 7 - Add another PageProducer component to the Web Module
The second page producer will be used to generate a response HTML page thanking survey
respondents for taking part in the survey. Set the Name property to SurveyResponsePageProducer.
Set the HTMLFile property to the Response.HTM file. The Response.HTM file contains the following
HTML strings.
<html>
<title>Thank You!</title>
<body>
<CENTER>
<h3>Thank You</h3>
<h3>for completing the</h3>
<h3>January 1998</h3>
<h3>David I</h3>
<h3>web survey</h3>
<img src="/images/davidi1.gif">
<p>
<img src="/images/davidsig.gif">
</CENTER>
</body>
</html>
I placed the Response.HTM html file in the same directory as my web server application DLL.
Step 8 - Bring up the Web Module Action Editor
Right mouse click in the Web Module window. Select the Action Editor menu item from the pop-up
menu.
Step 9 - Add the Survey Form default action item
In the Action Editor click the Add button. This will create a web action in the Web Module Actions
array. In the Inspector, set the Name property to WebSurveyDefaultAction. Set the Default property true - this will
mean that any execution of this web server application DLL will use this actions event handler for processing unless
a pathinfo string is found to match a user request (see the next step). Switch to the events tab in the inspector.
Double click in the OnAction event to create an event handler. Inside the event handler code put the following
line of code that will use the Page Producer to create the main survey form HTML page.
Response->Content = SurveyPageProducer->Content();
Step 10 - Add the Survey Response action item
Go back to the Editing WebSurveyModule->Actions window to create another action handler. This action
handler will be used to accept the data from the HTML form and store the data in the InterBase
database. In the Editing Actions window, click the Add button. In the Inspector, set the Name property
to WebSurveyPostInfo. Set the MethodType property to mtPost - this means this action handler will
only accept HTTP post messages. Set the PathInfo property (also called the URI in web circles) to the string /survey.
In the events tab of the Inspector, double click in the OnAction event to create an event handler for this web action.
When the user clicks the submit button on the HTML form, the form action will issue a HTTP post message with the
name of the DLL followed by the /survey string. The DLL will see this PathInfo string and know
that it is to fire the SurveyResponse action event handler. The code for the event handler will save
the data and use a Page Producer to send a thank you response to the browser.
// write out results of survey form to interbase database
for (int i=0 ; i < Request->ContentFields->Count ; i++) {
SurveyTable->Insert();
SurveyTableSURVEYNAME->AsString = "9801Survey";
SurveyTableQUESTIONNUMBER->AsInteger = i+1;
SurveyTableQUESTIONKEYWORD->AsString = Request->ContentFields->Names[i];
SurveyTableUSERANSWER->AsString =
Request->ContentFields->Values[Request->ContentFields->Names[i]];
SurveyTable->Post();
}
Response->Content = SurveyResponsePageProducer->Content();
Step 11 - Build the Web Server Application DLL
While in the environment, save the project and do a build of the web server application. This will create the .DLL file
in your project folder. Copy the generated DLL to your web server applications folder, usually
the SCRIPTS folder (or wherever you put your web applications). If you have previously tried
a build of your web server DLL you will need to shut down the web server in order to unload the DLL
from memory (if you don't you will get a sharing violation error, the DLL file is currently
in use).
Step 12 - Use your browser to try the Web Server application
Using your web browser type in the URL to your web server application DLL. You will key in something
like http://ww5.borland.com/scripts/websurvy.dll. This will cause your web server to load the
DLL into the same process space and activate the default action event for your web application. Since
the default activation event will generate an HTML form for the survey, you should see the HTML
form appear in your web browser. Select your choice of radion button answers to the questions and
click the submit button. The post action for this form will re-enter the DLL using the /survey
PathInfo string. The action event handler for the survey form will cause the code to execute to
save the survey form results into the InterBase database. You will see the survey response HTML page
in respond to a successful session with your web server application. If you have not set up the
database alias for the InterBase survey table, you will get error messages in your browser.
Good Luck Building Your Own Web Server Applications
We appreciate all those who filled out the C++ developer survey. Your continued
feedback will help us build the right products that fit all developer's current and future needs.

davidi@inprise.com
|
Connect with Us