1. Home
  2. Computing & Technology
  3. Delphi Programming
RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To
 
ISAPI tutorial for Delphi developers
Page 13: Database enabled applications - Part 1
 More of this Feature
• Pg 1: Intro to web-broker
• Pg 2: Using this tutorial
• Pg 3: Getting started
• Pg 4: Web Actions
• Pg 5: The first ISAPI app
• Pg 6: TWebRequestObject
• Pg 7: Request-responding
• Pg 8: TPageProducers
• Pg 9: Cookies made easy
• Pg 10: Stateless HTTP
• Pg 11: DB enabled apps
• Pg 12: FAQ
• Pg 14: DB apps - Part 2
• Pg 15: DB apps - Part 3
 Join the Discussion
"Post your questions, concerns, views and comments to this article..."
Discuss!
 Related Resources
• Internet programming
• CGI and ISAPI with Delphi

I am going to base chapter 11 on constructing a client database. In this part, I will show you how to setup the TDatabase and prepare the web-module for multiple accesses to the database. In the next part I will cover insertion and updates (deleting aswell) of records.

First of all, let's create our database. Run the SQL file DBSTRUCT.SQLto generate the database file. Make sure you change the machine.domain: c:\databases\client.gdb to the appropriate settings for your machine. Next, let's configure the BDE.

Like any other BDE application, during development I have set the ENABLE SCHEMA CACHE to False. On deployment, change this to TRUE. Before going any further, check to see everything is working ok by opening the database from the BDE.

Your BDE settings should look something like this:

BDE Administrator

Now that we have our database and BDE configured, let's start a new ISAPI project. Once this is done, drop a TDatabase and a TSession on the form and set the following properties for each one:

TDatabaseTSession
Alias = CLIENTAutoSessionName = True
LoginPrompt = False
Params:
 USER NAME=SYSDBA
 PASSWORD=masterkey
 DatabaseName = dbDATA
 Name = dbDATA

Of course, in real life you would not be setting the username and password at design time but at runtime. This is just for demonstration purposes. If you have Delphi 5, you will notice that the red circles will disappear in the designer as soon as you set the AutoSessionName = True. What this does is take care of giving each request a unique session to access the data safely and not interfere with any other petitions.

Now let's code a bit. We want to open the database when the DLL is first loaded and close it when the DLL is destroyed, thus preventing each request having to open/close the connection. To do this, we place the following code in the OnCreate/OnDestroy of the web module. Remember that this works as mentioned if you leave CacheConnections set to the default value of True. If you set CacheConnection to False (Application.CacheConnections := False), then every request will call the OnCreate/OnDestroy.

Next, we create a DEFAULT web action that just replies with 'Invalid Request'. Later on, when I make use of the BeforeDispatch we will see that we can control this there and not have to create a default action. In any case, it's not harmful and doesn't effect us at this point.

So this covers our first part of Page 11. Easy wasn't it? In the next part we are going to add the ability to insert/update and delete clients over the web.

Next page > Database enabled applications - Part 2 > Page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15

All graphics (if any) in this feature created by Zarko Gajic.

 More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: ADO Cursors - DB/10.
Chapter ten of the free Delphi Database Course for beginners. How ADO uses cursors as a storage and access mechanism, and what you should do to choose the best cursor for your Delphi ADO application.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Reader's Choice Award Winners

What are the best instant messengers, apps, editors and more? You told us, for our 2010 technology awards program. More >

iPad Central

Is Apple's new tablet computer impractical, a must-have -- or both? We'll help you figure it out. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2010 About.com, a part of The New York Times Company.

All rights reserved.