这是我的代码的简化示例,用于显示我的类的外观......两个类都在单独的 asp 文件中(newsitem.asp 和 messageboard.asp)
Class NewsItem
private c_title
private c_content
public property get title
title = c_title
end property
public property get content
content = c_content
end property
public function loadById (id)
'Fill all the variables with database records'
c_title = rs(...)
c_content = rs(...)
end function
End Class
Class MessageBoard
Dim dict
private sub Class_Initialize
set dict = Server.CreateObject("Scripting.Dictionary")
end sub
public property get messages ()
messages = dict
end property
public function fillBoard ()
Dim oNews : set oNews = new NewsItem
For all the newsitems in the database
oNews.loadByID(newsitemID)
dict.add newsitemsID, oNews
Next
end function
End Class
在第三个文件 (showMessageboard.asp) 中,我包含上述 2 个文件并尝试执行以下操作:
Dim oMB : set oMB = new MessageBoard
oMB.fillBoard() 'Dictionary of MessageBoard class is filled with NewsItem-objects'
response.write oMB.messages.item(1).content 'show the content of the first NewsItem-object'
我总是在最后一行收到一个错误,说明不支持该方法的对象属性(目前我不知道确切的错误消息,因为我不在家:) 稍后会添加)。
任何人都可以看看这段代码并告诉我可能出了什么问题吗?我通过将response.write dict.item(1).content添加到公共属性 get messages来测试我的代码,它工作正常。所以在课外使用字典时出了点问题???
我也尝试使用函数而不是public property,但结果相同......