[ 来源:www.it55.com | 作者: | 时间:2007-07-15 | 收藏 | 推荐 ] 【大 中 小】
如果你想脱离asp爱好者的水平,那么你就应该学会为asp编写组件。我在google上搜索了一下,Delphi编写asp组件的文章一共就几篇,所以今天写了这篇Delphi编写asp组件的基础文章,希望对新手有点帮助。如果你要学习VB编写asp组件的话,建议看看龙卷风大哥的文章(http://blog.csdn.net/online/category/9939.aspx),不是我可以比的。呵呵:)
开始吧,让我们一起编写一个”hello world!”的示例。我这里用的是Delphi 7。
1.文件->新建->其他->activex->activex Library,然后保存成showdll.dpr 免费资源www.it55.com
2.再次,文件->新建->其他->activex->activex Server Object,填写CoClassName:showhello,其他不变,点击ok。
免费资源www.it55.com
3.现在开始写程序,先添加一个方法。选择Ishowhello->右键->New->Method,填写方法名称:sayworld。
http://www.it55.com/
show.pas的全部代码如下: www.it55.com
unit show; vd;k;l www.it55.com rdfg
{$warn SYMBOL_PLATFORM OFF}
www.it55.com在线教程
interface
免费资源www.it55.com
uses www.it55.com
ComObj, ActiveX, AspTlb, showdll_TLB, StdVcl;
http://www.it55.com/
type 45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn
Tshowhello = class(TASPObject, Ishowhello)
IT资讯之家 www.it55.com
protected vd;k;l www.it55.com rdfg
procedure OnEndPage; safecall;
45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn
procedure OnStartPage(const AScriptingContext: IUnknown); safecall; sflj www.it55.com kg^&fgd
procedure sayworld; safecall; //sayworld方法 IT资讯之家 www.it55.com
end; www.it55.com
implementation
uses ComServ;
procedure Tshowhello.OnEndPage; 45398 www.it55.com it55学习IT知识,享受IT生活 4dfkjn
begin
sflj www.it55.com kg^&fgd
inherited OnEndPage; IT资讯之家 www.it55.com
end; sflj www.it55.com kg^&fgd
procedure Tshowhello.OnStartPage(const AScriptingContext: IUnknown); 免费资源www.it55.com
begin 免费资源www.it55.com
inherited OnStartPage(AScriptingContext); www.it55.com
end; sflj www.it55.com kg^&fgd
procedure Tshowhello.sayworld(); //定义sayworld方法
begin vd;k;l www.it55.com rdfg
response.write('hello world'); //里边的语法和asp一样的写法了,就在这里封装了。
end;
initialization
TAutoObjectFactory.Create(ComServer, Tshowhello, Class_showhello, www.it55.com在线教程
ciMultiInstance, tmApartment); 免费资源www.it55.com
end. http://www.it55.com/
4.点击运行,编译成dll, 并自动注册了。这时候会提示:

让你放到web服务器上运行,好了现在写个asp文件调用一下吧,注意Delphi已经生成了一个asp文件,我们改一下调用的方法就可以了。 www.it55.com在线教程
IT资讯之家 www.it55.com
<html> sflj www.it55.com kg^&fgd
<body> it55.com
<title> Testing Delphi ASP </TITLE>
<center>
<h3> You should see the results of your Delphi Active Server method below </H3> www.it55.com在线教程
</center>
sflj www.it55.com kg^&fgd
<hr> www.it55.com
<% Set DelphiASPObj = Server.CreateObject("showdll.showhello") it55.com
DelphiASPObj.sayworld IT资讯之家 www.it55.com
%>
<hr> http://www.it55.com/
</body> www.it55.com在线教程
</html> www.it55.com
在iis的站点下运行看看效果吧:
5.其他:
delphi编写的组件,用win2000的组件服务注册后可以看该组件的接口的方法 www.it55.com在线教程
it55.com
(编辑:IT资讯之家 www.it55.com)