当前位置: 移动技术网 > IT编程>开发语言>.net > 使用Delphi编写组件封装asp代码

使用Delphi编写组件封装asp代码

2018年10月07日  | 移动技术网IT编程  | 我要评论

广西柳州门,久佰年,印度电影一网打尽

    在asp程序中版权限制是直是个头疼问题,目前最常见的方法就是使用封装代码以达到的效果。我在网上搜索了一下,delphi编写组件的文章一共就几篇,所以今天写了这篇delphi编写asp组件的基础文章,希望对新手有点帮助。

    开始吧,让我们一起编写一个”hello world!”的示例。我这里用的是delphi 7。

    1.文件->新建->其他->activex->activex library,然后保存成showdll.dpr



2.再次,文件->新建->其他->activex->activex server object,填写coclassname:showhello,其他不变,点击ok。


3.现在开始写程序,先添加一个方法。选择ishowhello->右键->new->method,填写方法名称:sayworld。


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


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, 并自动注册了。这时候会提示:


让你放到web服务器上运行,好了现在写个asp文件调用一下吧,注意delphi已经生成了一个asp文件,我们改一下调用的方法就可以了。


修改后的showhello.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("showdll.showhello")

   delphiaspobj.sayworld

%>

<hr>

</body>

</html>

在iis的站点下运行看看效果吧:


5.其他:

delphi编写的组件,用win2000的组件服务注册后可以看该组件的接口的方法


6.还有asp页面和组件间传递参数,其实就是给调用的方法(函数)传递参数,注意delphi里定义的时候要和vbs 的数据类型一致。这些还是大家多实践吧。这里主要是想大家学会封装asp核心代码的方法,起个抛砖引玉的作用。

写这些,文字不多,就是截图麻烦了点。水平有限,错误的地方,大家拍砖,拍的轻点啊!!!!

技术交流 永无止境

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网