1. Tech

Your suggestion is on its way!

An email with a link to:


was emailed to:

Thanks for sharing About.com with others!

RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To
TASPObject - ASP programming with Delphi
Page 1: Your first ASP object in Delphi - using the Response.Write method
 More of this Feature
• Page 2: ASP page counter
• Page 3: Building a web site
 Join the Discussion
"Post your questions, concerns, views and comments to this article..."
 Related Resources
• Internet programming
• Using components
• CGI/ISAPI articles

Article submitted by: Curtis W. Socha, http://www.absolute-research.com

Introducing the TASPObject. See how to create a real application using Delphi that incorporates the TASPObject - by creating an ASP page counter to see how many times your ASP has been called.


Read before you start:
.Intro to ASP programming
.ASP Form Processing
.ASP Sessions
.ASP Meets COM
.ASP Applications
The purpose of this article is to teach you ASP from the ground up. You will save yourself a lot of headache if you already know a little HTML before starting to delve into this stuff. Also, you will need to learn VBScript and/or Javascript. Don't let that scare you. You can learn the scripting languages at the same time you learn ASP, it just takes a little more work.

   That’s nice. What in the heck is a TASPObject anyway?
The TASPObject gives you access to a plethora of ASP functionality yet keeps the majority of it within the Delphi language. How does it do this? Well, they have made a nice wrapper around the objects we use when writing an ASP page. They wrapped some native ASP objects like the Response, and Request object. They also put wrappers around some commonly used scripting objects like the Dictionary object. That said, I want you to think of a TASPObject as a regular COM object that gets called from your ASP page to do the dirty work for you in your native language. It’s easy and I’ll show you how to do it from the ground up!

   Cool! Can we start now?
Yep. Let’s get right to it! Follow these 19 steps to help you get up-and-running in no time at all ….

1) Open Delphi
2) Click File|New…
3) Select the ActiveX tab and click the ActiveX Library icon.
4) Again click the File|New… menu.
5) Select the ActiveX tab and click the Active Server Object icon.
6) When the following window pops up, type in AnAspTestObject then click OK.

New asp object

7) You will then see the Type Library editor pop up. Change the name of the Type Library AnASPObjectLibrary.
8) Also add a method to the IAnASPTestObject and name it SomeCall.
9) Click the Refresh icon on the Type Library screen.
10) Your Type Library should look like this…


11) At this point, you may have noticed that Delphi auto-created an .ASP for you. It should be named AnASPTestObject.Asp. This ASP will contain the following HTML and server side script:

  <TITLE> Testing Delphi ASP </TITLE> 
    <H3> You should see the results of your
		Delphi Active Server method below </H3> 
  <% Set DelphiASPObj = Server.CreateObject("Project1.AnASPTestObject") 
     DelphiASPObj.{Insert Method name here} 

12) The two sections I colored in Blue will need to be changed.
   a. Change the word Project1 to AnASPObjectLibrary in the ASP. The reason you need to do this should be obvious. The name of your Type Library is AnASPObject!
   b. Change the words {Insert Method name here} to SomeCall. This is the name of the method you added to the type library! Your HTML and scripts should now look like this:

  <TITLE> Testing Delphi ASP </TITLE> 
    <H3> You should see the results of your
		Delphi Active Server method below </H3> 
  <% Set DelphiASPObj = Server.CreateObject

13) Ok. Now for the fun stuff. Save all of your stuff and go to the unit that contains the implementation of the TAnASPObject class. You should see a procedure named SomeCall. Go ahead and change it so the procedure looks like this:

procedure TAnASPTestObject.SomeCall; 
  Response.Write('<Font face="Arial" Color="Red">'+ 
'For only $19.99, we will send you the infamous
cooking guide'' "How to Roast Cute Gerbils". 
But wait! There''s more! For an additional $5.00, 
we will send you not one, but TWO live gerbils for 
you to try out our cookbook with! Call now! Our 
representatives are waiting! 
Call 1-800-Mmm-Gerbils Today!' 

14) Now that we have fleshed out a simple reponse, we can actually compile and test our new TASPObject! This is a piece of cake as I’ll show you.
15) Compile your project.
16) Register your COM Object by selecting to Run|Register ActiveX Server.
17) Copy your ASP page into your C:\ASPLessons directory (The default web directory I have been using for these tutorials).
18) Open up I.E. and put in http://localhost/AnASPTestObject.ASP (If that is what you saved your ASP as)
19) You should see the following screen:

Testing ASP object

Click here to download the code for this: Lesson6_a.zip

Next page > Creating an ASP page counter to see how many times your Delphi ASP page has been called. > Page 1, 2

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: Windows XP Manifest in Delphi.
Find out how you can include the manifest into a Delphi project to allow your application to share the same look and feel of Windows XP.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter

 Got some code to share? Got a question? Need some help?

©2016 About.com. All rights reserved.