gpt4 book ai didi

asp-classic - 经典asp中的类结构

转载 作者:行者123 更新时间:2023-12-04 17:56:01 24 4
gpt4 key购买 nike

我需要在经典的 asp 中使用类结构。我写了以下三门课。

分类.asp

<%

Class Category

Private NameVar

Public Property Get Name()
Name = NameVar
End Property

Public Property Let Name(nameParam)
NameVar = nameParam
End Property

End Class

%>

项目.asp
<%

Class Item

Private NameVar
Private CategoryVar

Public Property Get Name()
Name = NameVar
End Property

Public Property Let Name(nameParam)
NameVar = nameParam
End Property

Public Property Get Category()
category = categoryVar
End Property

Public Property Let Category(categoryParam)
CategoryVar = categoryParam
End Property

End Class

%>

测试文件


<%

Dim CategoryVar
Set CategoryVar = New Category

CategoryVar.Name = "Weight"

Dim ItemVar
Set ItemVar = New Item

ItemVar.Name = "kg"
ItemVar.Category = CategoryVar

%>
<html>
<head>
<title>UoM Componet Testing</title>
</head>
<body>
<%= ItemVar.Name %><br/>
</body>
</html>

当我运行这段代码时,我发现了一些问题。错误是:

Microsoft VBScript runtime (0x800A01B6) Object doesn't support this property or method: 'CategoryVar'".



这怎么解释?请帮我。

最佳答案

在 VBScript 中,如果您知道属性将包含对象引用,则必须使用 Property Set 定义它。陈述。此外,您必须使用 Set 将对象引用分配给变量时的语句。考虑到这一点,需要进行以下更改:

项目.asp

Class Item

'<snip>

Public Property Get Category()
' Add Set here
Set category = categoryVar
End Property

' Change "Property Let" to "Property Set"
Public Property Set Category(categoryParam)
Set CategoryVar = categoryParam
End Property

End Class

测试文件

<%
' <snip>

ItemVar.Name = "kg"
Set ItemVar.Category = CategoryVar

%>

关于asp-classic - 经典asp中的类结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8786129/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com