用 Delphi 7 创建 ActiveX 组件交 ASP 使用

2 篇文章 0 订阅

一、启动 Delphi 7 ,新建 ActiveX  - ActiveX Library ;

二、引入类库先,若你的 Delphi 还没有引入 asp 组件的话。
Project - Import Type Library ,“Microsoft Active Server Pages Object Library(Version 3.0)”,对应的dll文件是:“系统盘:/Windows目录/system32/inetsrv/asp.dll”,为防止组件名称重复,将TRequest,TResponse,TSession 分别重命名为 TAspRequest,TAspResponse,TAspSession,再点击“Install...”。

三、新建 ActiveX - Automation Object ,coClassName ="test2",Instancing="Multiple Instance";

四、在"Itest2"上新建方法:
1、OnStartPage,参数:const unk:IUnknown,
2、OnEndPage
3、Test(测试方法)

五、代码:
unit Unit1;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, Project1_TLB, StdVcl,ASPTypeLibrary_TLB; //1

type
  TTestObject = class(TAutoObject, ITestObject)
  protected
    procedure OnStartPage(const unk: IUnknown); safecall;
    procedure OnEndPage; safecall;
    procedure test; safecall;
  end;

implementation

uses ComServ;

var
  m_scriptContext:IScriptingContext;  //2

procedure TTestObject.OnStartPage(const unk: IUnknown);
begin
  m_scriptContext:=unk as IScriptingContext;  //3
end;

procedure TTestObject.OnEndPage;
begin
  m_scriptContext:=nil;   //4
end;

//5
procedure TTestObject.test;
begin
  m_scriptContext.Response.Write('ActiveX test for Delphi');
  m_scriptContext.Response.Write('大家好,我是由Delphi创建的ActiveX组件的输出信息.');
end;

initialization
  TAutoObjectFactory.Create(ComServer, TTestObject, Class_TestObject,
    ciMultiInstance, tmApartment);
end.

 六、注册ActiveX组件:
regsvr32 Project1.dll
反注册是:regsvr32 /u Project1.dll

注:若Delphi需重新编译工程,而IIS又在用这个dll,则重启w3c服务才能断开iis与dll的连接,才能编译。

七、ASP使用:
<div>

 <%
 Dim obj
 Set obj=Server.CreateObject("Project1.TestObject")
 obj.test
 Set obj=nothing
 %>
 
 </div>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值