If you want to leave the level of ASP enthusiasts, then you should learn to write components for ASP. I searched on Google, and Delphi wrote a total of a total of a total of a total of a total of a total of a total, so I wrote this Delphi's basic article of the ASP component, I hope to help the novice. If you want to learn VB to write ASP components, it is recommended to look at the articles of the tornado big brother (http://blog.9cbs.net/online/category/9939.aspx), not I can ratio. Ha ha:)
Start, let's write an example of "Hello World!" Together. I use Delphi 7 here.
1. File -> New -> Others-> ActiveX-> ActiveX Library, then save to showdll.dpr
2. Re-, File -> New -> Others-> ActiveX-> ActiveX Server Object, fill in CoclassName: Showhello, other unchanged, click OK.
3. Now start writing a program, first add a method. Select ISHOWHELLO-> Right-click -> New-> Method, fill in the method name: SayWorld.
4. Start writing, save Unit1 into show.PAS, then add the method SayWorld code
SHOW.PAS all code is as follows:
UNIT SHOW;
{WARN SYMBOL_PLATFORM OFF}
Interface
Uses
Comobj, ActiveX, AspTLB, Showdll_TLB, STDVCL;
Type
Tshowhello = Class (TaspObject, Ishowhello)
protected
PROCEDURE OneendPage; SaFECALL;
Procedure OnStartPage (Const AscriptingContext: IUNKNOWN); SaFECALL;
Procedure sayworld; saFECALL; // SayWorld method
END;
IMPLEMentation
Uses Comserv;
Procedure tshowhello.onendpage;
Begin
Inherited oneundpage;
END;
Procedure Tshowhello.onStartPage (Const AscriptingContext: iUnknown);
Begin
Inherited OnStartPage (AscriptingContext);
END;
Procedure tshowhello.sayworld (); // Define SayWorld method
Begin
Response.write ('Hello World'); // The syntax in // is the same as the ASP, and it is packaged here.
END;
INITIALIZATION
TautoobjectFactory.create (Comserver, Tshowhello, Class_Showhello,
CIMULTIINSTANCE, TMAPARTMENT);
End.
4. Click to run, compile into a DLL, and register it automatically. At this time, you will prompt:
Let you run on the web server, I'm writing an ASP file call, pay attention to Delphi has generated an ASP file, and we can change the way to call.
The modified Showhello.asp code is as follows:
<% Set delphiaspobj = server.createObject ("showdll.showhello")
Delphiaspobj.sayworld
%>
Body>
Html>
Run the effect under the IIS site:
5. other:
Components written in Delphi, can see the interface of the assembly after registering with Win2000 component service
6. There are also ASP pages and components to deliver parameters, in fact, to pass parameters to the modified method (function), pay attention to the data type of VBS when defined in Delphi. These are still more practical. Here is mainly what you want to learn to encapsulate the ASP core code, and you will have a role in tile jade.
Write these, there are not many words, is the screenshots. Limited horizontal, wrong place, everyone taking bricks, taking a light! ! ! !
A wind and one cloud
2004-10-18