我建了一个ActiveX DLL 工程,有A,B,C,D四个CLASS,其中A的Instancing属性为Multiuse,其余的都为Private。关系是A调用B,B调用C,C调用D。编译成DLL后测试是通过的,但我把它添加了一些代码(实现共享的)配置成COM+后,就出现了些问题,原来保存在D中的变量,现在无法取到了,不知道是什么原因?相关代码如下:
A:Implements ObjectControlPrivate objExtractor As B
Private objContext As ObjectContext'-----------------------------
' 实现COM+激活时进行的操作
' 读入提取规则,并存储
'-----------------------------
Private Sub ObjectControl_Activate()
Dim strRule As String
'从数据库中取得规则字符串
strRule = GetPatternRule()
'设置COM+共享常量值为取到的规则串
SetSPM "GroupConverter", "PropConverter", strRuleEnd SubPrivate Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = True
End Function'--------------------------------------
' COM+停止事件
'--------------------------------------
Private Sub ObjectControl_Deactivate()
objContext.SetComplete
objContext.SetAbort
End Sub
'-------------
'设置一个值
'-------------
Private Sub SetSPM(ByVal strGroup As String, ByVal strProperty As String, ByVal strValue As String)
Dim objContext As ObjectContext
Set objContext = GetObjectContext()
Dim spmMgr As SharedPropertyGroupManager
Dim spmGroup As SharedPropertyGroup
Dim spmProp As SharedProperty
Dim groupExists As Boolean
Dim propExists As Boolean
Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
Set spmGroup = spmMgr.CreatePropertyGroup(strGroup, LockSetGet, Process, groupExists)
Set spmProp = spmGroup.CreateProperty(strProperty, propExists) spmProp.Value = strValue objContext.SetComplete
objContext.EnableCommit
End Sub
'-------------
'取得一个值
'-------------
Private Function GetSPM(ByVal szGroup As String, ByVal szProperty As String) As String
'....与SetSPM是相反的过程
End FunctionPrivate Function testDo()End Function
Public Function GetGender() As String
GetGender=B.CommonField("Gender")
End FunctionPublic Function testMsg()
Dim ss As String, strContent As String
ss = GetSPM("GroupConverter", "PropConverter")
B.SetPatternRule ss
B.Extract "内容 性别:男"
'执行后性别结果会保存在D类的Dictionary中的,透过B类的CommonField属性来取得
End Function测试程序调用:
Dim obj As Object
Set obj = CreateObject("Converter.A")
obj.testMsg
Debug.Print obj.GetGender
这样返回的性别是空的!
但如果将A类中的testMsg函数改成这样,则能取到正确结果
Public Function testMsg() As String
Dim ss As String, strContent As String
ss = GetSPM("GroupConverter", "PropConverter")
B.SetPatternRule ss
B.Extract "内容 性别:男"
testMsg=B.CommonField("Gender")
'执行后性别结果会保存在D类的Dictionary中的,透过B类的CommonField属性来取得
End Function
测试时调用
debug.print testMsg()这是为什么呀??
有点乱,不知道大家有没明白我说的 :)
A:Implements ObjectControlPrivate objExtractor As B
Private objContext As ObjectContext'-----------------------------
' 实现COM+激活时进行的操作
' 读入提取规则,并存储
'-----------------------------
Private Sub ObjectControl_Activate()
Dim strRule As String
'从数据库中取得规则字符串
strRule = GetPatternRule()
'设置COM+共享常量值为取到的规则串
SetSPM "GroupConverter", "PropConverter", strRuleEnd SubPrivate Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = True
End Function'--------------------------------------
' COM+停止事件
'--------------------------------------
Private Sub ObjectControl_Deactivate()
objContext.SetComplete
objContext.SetAbort
End Sub
'-------------
'设置一个值
'-------------
Private Sub SetSPM(ByVal strGroup As String, ByVal strProperty As String, ByVal strValue As String)
Dim objContext As ObjectContext
Set objContext = GetObjectContext()
Dim spmMgr As SharedPropertyGroupManager
Dim spmGroup As SharedPropertyGroup
Dim spmProp As SharedProperty
Dim groupExists As Boolean
Dim propExists As Boolean
Set spmMgr = CreateObject("MTxSpm.SharedPropertyGroupManager.1")
Set spmGroup = spmMgr.CreatePropertyGroup(strGroup, LockSetGet, Process, groupExists)
Set spmProp = spmGroup.CreateProperty(strProperty, propExists) spmProp.Value = strValue objContext.SetComplete
objContext.EnableCommit
End Sub
'-------------
'取得一个值
'-------------
Private Function GetSPM(ByVal szGroup As String, ByVal szProperty As String) As String
'....与SetSPM是相反的过程
End FunctionPrivate Function testDo()End Function
Public Function GetGender() As String
GetGender=B.CommonField("Gender")
End FunctionPublic Function testMsg()
Dim ss As String, strContent As String
ss = GetSPM("GroupConverter", "PropConverter")
B.SetPatternRule ss
B.Extract "内容 性别:男"
'执行后性别结果会保存在D类的Dictionary中的,透过B类的CommonField属性来取得
End Function测试程序调用:
Dim obj As Object
Set obj = CreateObject("Converter.A")
obj.testMsg
Debug.Print obj.GetGender
这样返回的性别是空的!
但如果将A类中的testMsg函数改成这样,则能取到正确结果
Public Function testMsg() As String
Dim ss As String, strContent As String
ss = GetSPM("GroupConverter", "PropConverter")
B.SetPatternRule ss
B.Extract "内容 性别:男"
testMsg=B.CommonField("Gender")
'执行后性别结果会保存在D类的Dictionary中的,透过B类的CommonField属性来取得
End Function
测试时调用
debug.print testMsg()这是为什么呀??
有点乱,不知道大家有没明白我说的 :)
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货