- ·上一篇文章:asp域名查询代码
- ·下一篇文章:适合所有表的添加、删除、修改的函数
关于script的dictionary对象的用法
关于script的dictionary对象,其实我想一开始ms是借鉴了python之类的动态脚本语言的,而且是面对客户端开发的关于这一点可以参考wrox的asp程序员参考手册里第137页里,如果在session级保存一个dictionary对象会降低系统的性能,而在application级保存一个dictionary对象会导致web服务器崩溃,关于这个就不在多说了。
现在我们要考虑的是dictionary对象在单页的时候,有哪些设计时的缺陷:
大家可以这么试试
set 
rs=server.createobject("
adodb.recordset"
)
sql="
select 
* 
from 
table"
rs.open 
sql,conn,1,3
set 
ttt=server.createobject("
scripting.dictionary"
)
ttt.add 
"
xxx"
,rs("
field"
)
set 
rs=nothing
liu=ttt("
xxx"
) 
&
#39
当你这么做的时候会发现一件什么事呢?asp页会告诉你发生意外!!这个就很令人诧异了,什么是意外呢?很难说,后来经过我反复的测试发现是因为不能把rs("
field"
)的值直接给dictionary对象,经过反复研究得出的结论是如下的:dictionry是把rs("
field"
)的内存地址给储存了,这样的话,我刚才写的那个无疑是一种灾难,解决方法是把这个rs("
field"
)放到一个变量里就可以解决了,但是dictionary对象难道不可以保存一个被nothing过的对象么?这个就是一个很大的疑问了,所以我又写了这么一段程序,大家可以保存成try.htm看看效果的
<
script 
language=&
#39
vbscript&
#39
>
set 
ttt=createobject("
scripting.dictionary"
)
ttt.add 
"
liu"
,"
uuu"
set 
ddd=createobject("
scripting.dictionary"
)
ddd.add 
"
ppp"
,ttt
set 
ttt=nothing
bbb=ddd("
ppp"
)("
liu"
)
alert(bbb)
<
/script>
结果是什么?你会发现一段alert了uuu说明是没有问题的,这就说明dictionary对象其实是把另一个
dictionary对象整个clone进来了,这就更验证了wrox的书中写的,dictionary对象在ms开发的时候其
实是针对客户端的,这种说法了
还有对数组与dictionary合用的代码也可以给大家看看的
<
script 
language=&
#39
vbscript&
#39
>
i=1
picname=("
xxx"
)
str="
set 
"
 
&
#38
 
"
pic_"
 
&
#38
 
i 
&
#38
 
"
=createobject("
 
&
#38
 
"
"
"
"
 
&
#38
 
"
scripting.dictionary"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
)"
execute(str)
str="
pic_"
 
&
#38
 
i 
&
#38
 
"
.add 
"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
picname"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
,"
 
&
#38
 
"
"
"
"
 
&
#38
 
picname 
&
#38
 
"
"
"
"
execute(str)
dim 
ttt()
redim 
ttt(5)
ttt(0)="
uuu"
pic_1.add 
"
item"
,ttt
liu=pic_1("
picname"
)
set 
pic_2=createobject("
scripting.dictionary"
)
erase 
ttt
redim 
ttt(5)
ttt(0)="
iii"
nnn=pic_1("
item"
)(0)
pic_2.add 
"
rrr"
,ttt
zzz=pic_2("
rrr"
)(0)
alert(liu)
alert(nnn)
alert(zzz)
<
/script>
现在我们要考虑的是dictionary对象在单页的时候,有哪些设计时的缺陷:
大家可以这么试试
set 
rs=server.createobject("
adodb.recordset"
)
sql="
select 
* 
from 
table"
rs.open 
sql,conn,1,3
set 
ttt=server.createobject("
scripting.dictionary"
)
ttt.add 
"
xxx"
,rs("
field"
)
set 
rs=nothing
liu=ttt("
xxx"
) 
&
#39
当你这么做的时候会发现一件什么事呢?asp页会告诉你发生意外!!这个就很令人诧异了,什么是意外呢?很难说,后来经过我反复的测试发现是因为不能把rs("
field"
)的值直接给dictionary对象,经过反复研究得出的结论是如下的:dictionry是把rs("
field"
)的内存地址给储存了,这样的话,我刚才写的那个无疑是一种灾难,解决方法是把这个rs("
field"
)放到一个变量里就可以解决了,但是dictionary对象难道不可以保存一个被nothing过的对象么?这个就是一个很大的疑问了,所以我又写了这么一段程序,大家可以保存成try.htm看看效果的
<
script 
language=&
#39
vbscript&
#39
>
set 
ttt=createobject("
scripting.dictionary"
)
ttt.add 
"
liu"
,"
uuu"
set 
ddd=createobject("
scripting.dictionary"
)
ddd.add 
"
ppp"
,ttt
set 
ttt=nothing
bbb=ddd("
ppp"
)("
liu"
)
alert(bbb)
<
/script>
结果是什么?你会发现一段alert了uuu说明是没有问题的,这就说明dictionary对象其实是把另一个
dictionary对象整个clone进来了,这就更验证了wrox的书中写的,dictionary对象在ms开发的时候其
实是针对客户端的,这种说法了
还有对数组与dictionary合用的代码也可以给大家看看的
<
script 
language=&
#39
vbscript&
#39
>
i=1
picname=("
xxx"
)
str="
set 
"
 
&
#38
 
"
pic_"
 
&
#38
 
i 
&
#38
 
"
=createobject("
 
&
#38
 
"
"
"
"
 
&
#38
 
"
scripting.dictionary"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
)"
execute(str)
str="
pic_"
 
&
#38
 
i 
&
#38
 
"
.add 
"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
picname"
 
&
#38
 
"
"
"
"
 
&
#38
 
"
,"
 
&
#38
 
"
"
"
"
 
&
#38
 
picname 
&
#38
 
"
"
"
"
execute(str)
dim 
ttt()
redim 
ttt(5)
ttt(0)="
uuu"
pic_1.add 
"
item"
,ttt
liu=pic_1("
picname"
)
set 
pic_2=createobject("
scripting.dictionary"
)
erase 
ttt
redim 
ttt(5)
ttt(0)="
iii"
nnn=pic_1("
item"
)(0)
pic_2.add 
"
rrr"
,ttt
zzz=pic_2("
rrr"
)(0)
alert(liu)
alert(nnn)
alert(zzz)
<
/script>
关于script的dictionary对象的用法