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.
Introduction
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.
Thats 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. Its easy and Ill show you how to do it from the ground up!
Cool! Can we start now?
Yep. Lets 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.
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:
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your
Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject("Project1.AnASPTestObject")
DelphiASPObj.{Insert Method name here}
%>
<HR>
</BODY>
</HTML>
|
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:
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> You should see the results of your
Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set DelphiASPObj = Server.CreateObject
("AnASPObjectLibrary.AnASPTestObject")
DelphiASPObj.SomeCall
%>
<HR>
</BODY>
</HTML>
|
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;
begin
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!'
);
end;
|
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 Ill 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:
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