Basic Steps for compiling ASP code by using Delphi (ASP Component Series)

Source: Internet
Author: User

 

If you want to break away from ASP fans, you should learn to write components for ASP. I searched on Google and wrote a few ASP Component articles in Delphi. So today I wrote this basic article on ASP Component compiling in Delphi, hoping to help beginners. If you want to learn VB to write ASP components, it is recommended to look at the tornado brother article (http://blog.csdn.net/online/category/9939.aspx), not I can compare. Haha :)

Let's get started. Let's write a "hello World!" together !" . I use Delphi 7 here.

1. Choose File> New> Other> ActiveX library and save it as showdll. DPR.

2. Again, choose File> New> Other> ActiveX Server Object, enter coclassname: showhello, and click OK.

3. Write the program now. Add a method first. Choose ishowhello-> right-click-> New-> method, and enter the method name sayworld.


4. Now write the program, save unit1 as show. Pas, and add the sayworld method code.

The 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 (); // defines the sayworld Method

Begin

Response. Write ('Hello World'); // The syntax inside is the same as that in ASP, And it is encapsulated here.

End;

 

Initialization

Tautoobjectfactory. Create (comserver, tshowhello, class_showhello,

Cimultiinstance, tmapartment );

End.

4. Click Run, compile it into a DLL, and register it automatically. At this time, the system will prompt:


Let's put it on the Web server and run it. Now, write an ASP file and call it. Note that Delphi has generated an ASP file. Let's change the called method.


The modified showhello. ASP code is as follows:

<HTML>

<Body>

<Title> testing Delphi ASP </title>

<Center>

<H3> You shoshould see the results of your Delphi Active Server method below

</Center>

<HR>

<% Set delphiaspobj = server. Createobject ("showdll. showhello ")

Delphiaspobj. sayworld

%>

<HR>

</Body>

</Html>

Run it on the IIS Site to see the effect:

5. Others:

The component compiled by Delphi. After registering with Win2000 component service, you can view the interface method of this component.


6. parameters are also transferred between ASP pages and components. In fact, parameters are passed to the called method (function). Note that the data type defined in Delphi must be consistent with that defined in vbs. Let's talk about this. Here, I want you to learn how to encapsulate the core ASP code and play an interesting role.

 

There are not many words to write, which is a bit of trouble. The level is limited. If something is wrong, you can make a brick and take a nap !!!!

Yifeng Yiyun

2004-10-18

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.