首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

VB写的DLL在ASP里调用时报“未设置对象变量或 With block 变量”异常

2012-03-06 
VB写的DLL在ASP里调用时报“未设置对象变量或 With block 变量”错误小弟写的这个DLL结构如下:Name MyDLL

VB写的DLL在ASP里调用时报“未设置对象变量或 With block 变量”错误
小弟写的这个DLL结构如下:
Name= "MyDLL "
两个类:
Class=x;   x.cls
Class=y;   y.cls
没有公共类

其中:Class=x;   x.cls   代码如下:
Public   ScriptingContext   As   ScriptingContext
Public   Application   As   Application
Public   Request   As   Request
Public   Response   As   Response
Public   Server   As   Server
Public   Session   As   Session

Public   Sub   OnStartPage(PassedScriptingContext   As   ScriptingContext)
        Set   ScriptingContext   =   PassedScriptingContext
        Set   Application   =   ScriptingContext.Application
        Set   Request   =   ScriptingContext.Request
        Set   Response   =   ScriptingContext.Response
        Set   Server   =   ScriptingContext.Server
        Set   Session   =   ScriptingContext.Session
End   Sub
Public   Sub   OnEndPage()
        Set   ScriptingContext   =   Nothing
        Set   Application   =   Nothing
        Set   Request   =   Nothing
        Set   Response   =   Nothing
        Set   Server   =   Nothing
        Set   Session   =   Nothing
End   Sub

Public   Function   f1(   str   )
        Response.Write   str
End   Function

Class=y;   y.cls   代码如下:
Public   ScriptingContext   As   ScriptingContext
Public   Application   As   Application
Public   Request   As   Request
Public   Response   As   Response
Public   Server   As   Server
Public   Session   As   Session

Public   Sub   OnStartPage(PassedScriptingContext   As   ScriptingContext)
        Set   ScriptingContext   =   PassedScriptingContext
        Set   Application   =   ScriptingContext.Application
        Set   Request   =   ScriptingContext.Request
        Set   Response   =   ScriptingContext.Response
        Set   Server   =   ScriptingContext.Server
        Set   Session   =   ScriptingContext.Session
End   Sub
Public   Sub   OnEndPage()
        Set   ScriptingContext   =   Nothing
        Set   Application   =   Nothing
        Set   Request   =   Nothing
        Set   Response   =   Nothing
        Set   Server   =   Nothing
        Set   Session   =   Nothing
End   Sub

Public   Function   f1(   str   )
      f1   =   x.f1(   str   )
End   Function

ASP调用:
<%
dim   mydll
set   mydll   =   Server.CreateObject( "MyDLL.y ")
mydll.f1   "AAAAA "


set   mydll   =   nothing
%>

因为两个类的方法   f1   的代码是一样,所以想让   y   直接调用   x   的方法,编译通过,但在ASP中调用时出现“未设置对象变量或   With   block   变量”的错误。

后来在y.cls里再加如下代码:
Public   x   As   x
...
set   x   =   new   x
...
也不行

再改:
Public   x1   As   x
...
set   x1   =   new   x
...
Public   Function   f1(   str   )
      f1   =   x1.f1(   str   )
End   Function

还是提示“未设置对象变量或   With   block   变量”

请问这是什么原因啊?
在线等
谢谢

[解决办法]
set x = new x
改成
set x = Server.CreateObject( "MyDLL.x ")

OnStartPage和OnEndPage是给ASP用的,必须用Server.CreateObject

热点排行