您的位置:首页 > 编程语言 > ASP

一个用delphi开发asp组件的例子

2008-11-28 21:45 330 查看
打开delphi,点击菜单 File->New->Other 选择Activex->Activex Library 保存项目为HelloWorld.dpr
继续选择菜单File->New->Other 选择 Activex->Active Server Object 在CoClass Name 中添入hello
保存库文件为 helloASP.pas 保存asp文件为hello.asp
选择 Ihello节点 右击 New->Method 新建一个方法 将方法名(name)改为 test 在helloasp.pas中的test的实现部分填加下列代码
response.Write('Hello World!');
在hello.asp中替换{Insert Method name here}为test 方法
然后保存全部工程文件,选择 Run->Register Activex Server 注册组件

将hello.asp文件复制到你的iis中执行asp的文件夹,执行即可。

/*------------------------
下面是全部 HelloASP.pas 代码
----------------------------*/
unit helloASP;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
ComObj, ActiveX, AspTlb, HelloWorld_TLB, StdVcl;

type
Thello = class(TASPObject, Ihello)
protected
procedure OnEndPage; safecall;
procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
procedure test; safecall;
end;

implementation

uses ComServ;

procedure Thello.OnEndPage;
begin
inherited OnEndPage;
end;

procedure Thello.OnStartPage(const AScriptingContext: IUnknown);
begin
inherited OnStartPage(AScriptingContext);
end;

procedure Thello.test;
begin
response.Write('Hello World!');
end;

initialization
TAutoObjectFactory.Create(ComServer, Thello, Class_hello,
ciMultiInstance, tmApartment);
end.

/*------------------------------------------------------
下面是hello.asp代码
-------------------------------*/
<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("HelloWorld.hello")
DelphiASPObj.test
%>
<HR>
</BODY>
</HTML>

/*------------------------------------
helloworld.dpr 文件代码
-------------------------------------*/
library HelloWorld;

{%File 'hello.asp'}

uses
ComServ,
HelloWorld_TLB in 'HelloWorld_TLB.pas',
helloASP in 'helloASP.pas' {hello: CoClass};

exports
DllGetClassObject,
DllCanUnloadNow,
DllRegisterServer,
DllUnregisterServer;

{$R *.TLB}

{$R *.RES}

begin
end.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: