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 10: Overcoming HTTP's Stateless nature
 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 11: DB enabled apps
• Pg 12: FAQ
• Pg 13: DB apps - Part 1
• 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

As I mentioned in Page 1, HTTP is a stateless protocol. To overcome this problem we can resort to various methods. The three most common ones are: Cookies, (Fat) URL's., and Hidden Fields.

I will discuss briefly all three methods. Personally I like the use of cookies. I have seen a lot of questions on the newsgroups with a short parenthesis saying "I don't want to use cookies". As I mentioned in the previous chapter, cookies is a very debated issue and I'm not going to add to it. I just think that if they are used in the correct way they can save you a lot of work. However, if you are still against using cookies, I will describe other methods to maintain state information. You can then pick which ever one suites your needs and taste better.

Since I will be making great use of cookies in the next chapter and later, I will not explain this method now. Basically it boils down to keeping an ID as a pointer to a record in a database, a file on disk and so on. Normally you shouldn't use cookies to maintain large amounts of information for two reasons: first of all they are limited in size and second of all they are not very *secure* as we could say. Anyone can examine the contents of a cookie. Keeping information like passwords, etc in there isn't wise. Instead you could keep an integer value for example that points to a record where the user's personal information is stored. You could also opt for encoding the information before sending it to the cookie and then decoding when retrieving, but really I don't see much point into going to all the trouble.

Having said that, let's examine the other two methods for passing information from one state to another.

   URL's
One of the easiest and most commonly used methods for passing information is using the URL. To pass information from one request to another using the URL can be easily accomplished using the SendRedirect method:

Response.SendRedirect('http://localhost/scripts/example.dll/redirect?params='+Request.ContentFields.Values['THE_FIELD']).

In this line, we are calling our dll again. However we are also passing information that we retrieved in this action from the content fields of the form (in particular THE_FIELD field).

Notice, that in the new call (redirect), you would only have access to the information via the QueryFields.

   HIDDEN FIELDS
Sometimes it's not adequate to pass information via the URL. Also you might want to use the information from the previous state in a new form and therfor have access to it with the ContentFields. To acheive this you can use hidden fields. Hidden fields are like any other HTML field except that they are "hidden", i.e. not visible to the user. Passing information in hidden fields is very simple with the use of tags.

Let's say you have an HTML form that calls an action in your DLL. Add to this form a hidden field and set the value to be equal to an html transparent tag, as in:

In your call to the DLL, put a PageProducer and replace the value of the tag with the information you need to pass to the next request.

if TagString = 'STATE_FIELD1' then ReplaceText := 'State_information';

Also make sure of course that the result is contained in a form so you could then have access to this field with the ContentFields property. In you next action, all you need to do to read this information is:

Request.ContentFields.Values['STATE_FIELD1'].

This method implies a bit more work on your part the using URL's or cookies to pass information. Also all the pages have to be processed with a PageProducer.

Next page > Database enabled applications > 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

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

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

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

All rights reserved.