If you want to get out of the ASP enthusiast's level, then you should learn to write components for ASP. I search on Google, Delphi writing ASP components of a total of several, so today wrote this Delphi writing ASP components of the basic article, I hope the novice a little help.
Let's start by writing a "Hello world!" An example. I'm here with Delphi 7.
1. File-> new-> other->activex->activex Library, then save into SHOWDLL.DPR
2. Again, file-> new-> other->activex->activex Server Object, fill Coclassname:showhello, other unchanged, click OK.
3. Start writing the program now, add a method first. Select Ishowhello-> Right->new->method, fill in the method name: Sayworld.
4. Now start writing the program, save Unit1 as Show.pas, and then add the method sayworld code
The full code for Show.pas is as follows:
Unit Show;
{$WARN Symbol_platform off}
Interface
Uses
Comobj, ActiveX, Asptlb, Showdll_tlb, STDVCL;
Type
Tshowhello = Class (Taspobject, Ishowhello)
Protected
Procedure OnEndPage; Safecall;
Procedure OnStartPage (const ascriptingcontext:iunknown); Safecall;
Procedure Sayworld; Safecall; Sayworld method
End
Implementation
Uses Comserv;
Procedure Tshowhello.onendpage;
Begin
Inherited OnEndPage;
End
Procedure Tshowhello.onstartpage (const ascriptingcontext:iunknown);
Begin
Inherited OnStartPage (Ascriptingcontext);
End
Procedure Tshowhello.sayworld (); Defining Sayworld Methods
Begin
Response. Write (' Hello world '); The syntax is the same as the ASP, it is encapsulated here.
End
Initialization
Tautoobjectfactory.create (COMServer, Tshowhello, Class_showhello,
Cimultiinstance, tmapartment);
End.
4. Click Run, compile into DLL, and register automatically. This will prompt:
Let you put on the Web server to run, OK now write an ASP file call it, note that Delphi has generated an ASP file, we change a downward use of the method can be.
The modified showhello.asp code is as follows:
<HTML>
<BODY>
<TITLE> Testing Delphi ASP </TITLE>
<CENTER>
<H3> you should to results of your Delphi Active Server method below </H3>
</CENTER>
<HR>
<% Set delphiaspobj = Server.CreateObject ("Showdll.showhello")
Delphiaspobj.sayworld
%>
<HR>
</BODY>
</HTML>
Run it under the IIS site to see how it works:
5. Other:
Delphi written components, with the Win2000 Component Services registered can look at the interface of the component method
6. There are ASP pages and components passed between parameters, in fact, is to call the method (function) to pass parameters, note that the definition of Delphi and the VBS data type consistent. This is more than everyone practice it. Here is the main want to learn how to encapsulate the ASP core code method, to play a role.
Write these, the text is not much, is the screenshot trouble point. The level is limited, the mistake place, everybody pats the brick, pats the light point AH!!!!
A cloud of wind and a
2004-10-18