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

Delphi编写组件封装asp代码的基本步骤(Asp组件系列)

2012-01-16 05:11 731 查看
======================================================

注:本文源代码点此下载

======================================================

如果你想脱离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


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
2.再次,文件->新建->其他->activex->activex server object,填写coclassname:showhello,其他不变,点击ok。


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
3.现在开始写程序,先添加一个方法。选择ishowhello->右键->new->method,填写方法名称:sayworld。


screen.width-333)this.width=screen.width-333" border="0">

4.现在开始写程序,将unit1保存成show.pas,然后添加方法sayworld的代码


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
show.pas的全部代码如下:
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方法
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(); //定义sayworld方法
begin
response.write('hello world'); //里边的语法和asp一样的写法了,就在这里封装了。
end;
initialization
tautoobjectfactory.create(comserver, tshowhello, class_showhello,
cimultiinstance, tmapartment);
end.
4.点击运行,编译成dll, 并自动注册了。这时候会提示:


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
让你放到web服务器上运行,好了现在写个asp文件调用一下吧,注意delphi已经生成了一个asp文件,我们改一下调用的方法就可以了。


screen.width-333)this.width=screen.width-333" border="0"
longdesc="">
修改后的showhello.asp代码如下:
html>
testing delphi asp
you should see the results of your delphi active server method below
在iis的站点下运行看看效果吧:


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
5.其他:
delphi编写的组件,用win2000的组件服务注册后可以看该组件的接口的方法


screen.width-333)this.width=screen.width-333"
border="0" longdesc="">
6.还有asp页面和组件间传递参数,其实就是给调用的方法(函数)传递参数,注意delphi里定义的时候要和vbs 的数据类型一致。这些还是大家多实践吧。这里主要是想大家学会封装asp核心代码的方法,起个抛砖引玉的作用。
写这些,文字不多,就是截图麻烦了点。水平有限,错误的地方,大家拍砖,拍的轻点啊!!!!
转载地址:http://www.log.org.cn/article.asp?id=24
绿色通道:好文要顶关注我收藏该文与我联系



======================================================

在最后,我邀请大家参加新浪APP,就是新浪免费送大家的一个空间,支持PHP+MySql,免费二级域名,免费域名绑定
这个是我邀请的地址,您通过这个链接注册即为我的好友,并获赠云豆500个,价值5元哦!短网址是http://t.cn/SXOiLh我创建的小站每天访客已经达到2000+了,每天挂广告赚50+元哦,呵呵,饭钱不愁了,\(^o^)/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: