📄 5.htm
字号:
<pre style="line-height: 25px"><% Application ("Obj1). MyObjMethod" % ></pre>
</font>
</div>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
或者使用本机的一个物件备份:</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><%
Set MyLocalObj1 = Application ("Obj1")
MyLocalObj1.MyObjMethod
%></pre>
</font>
</div>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
另外一种建立全域变数的方法是在Global.asa档案中使用 <OBJECT> 标记来实现。若需更多的资讯,请参阅
第7章〈指令档参考〉中的〈Global.asa Reference〉 。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">您不能在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>物件中储存内建物件。例如,下面的每一行都会传回错误讯息:</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><%
Set Application ("Var1") = Session
Set Application ("Var2") = Request
Set Application ("Var3") = Response
Set Application ("Var4") = Server
Set Application ("Var5") = Application
Set Application ("Var6") = ObjectContext
%></pre>
</font>
</div>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
您应该对任何全域元件所使用的模型都加以熟悉。用来开发元件的模型对於某个元件例项是否应被指定给某个<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>集合中的一个变数来说有显着的影响。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">如果在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>物件中储存了一个阵列,那麽请您不要直接存取阵列中的元素。例如,下面的指令档就不能执行。</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><% Application ("Stored Array")(3) = "New value" %></pre>
</font>
</div>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
这是因为Application物件被当做一个集合执行,阵列元素StoredArray(3)并没有收到新值。相反地,这个值被包含在Application物件集合中,并且会覆盖在相同阵列元素上的任何资料。</font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
如果在Application物件中储存了一个阵列,那麽最好在检索或改变阵列中的任何一个元素之前备份这个阵列。当使用完这个阵列时,您应该在Application物件中储存它,以便储存您所做的变更。以下指令档可以说明这种情况:</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px">--file1.asp--
<%
'Creating and initializing the array.
dim MyArray ()
Redim MyArray (5)
MyArray (0) = "hello"
MyArray (1) = "some other string"
'Storing the array in the Application object.
Application.Lock
Application ("Stored Array") = MyArray
Application.Unlock
Server.Transfer ("file2.asp")
%>
--file2.asp--
<%
'Retrieving the array from the Application Object
'and modifying its second element.
LocalArray = Application ("Stored Array")
LocalArray (1) = "there"
'Printing out the string "ello there."
Response.Write ( LocalArray (0)& LocalArray (1))
'Re-storing the array in the Application object.
'this overwrites the values in StoredArray with the new values.
Application.Lock
Application ("Stored Array") = LocalArray
Application.Unlock
%></pre>
</font>
</div>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">范例<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
下面的范例利用应用程式变数<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> NumVisits </b></font>来储存某个特定网页被存取的次数。使用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> lock </b></font>方法是用来确保只有目前的用户端能够存取或改变NumVisits。使用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Unlock </b></font>方法则是为了让其它的使用者能够存取<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>物件。</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><%
Application.Lock
Application ("NumVisits") = Application ("NumVisits") + 1
Application.Unlock
%>
This application page has been visited
<%= Application ("NumVisits") %> times!</pre>
</font>
</div>
<p><font face="arial" color="#3e72d7" size="4" style="line-height: 25px">
<b style="line-height: 25px">Application集合<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Application </b></font>物件支援下面这些集合:</font></p>
<font face="arial" color="#000000" size="2" style="line-height: 25px">
<ul style="line-height: 25px">
<li style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Contents </b></font><br style="line-height: 25px">
</li>
<li style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> StaticObjects </b></font><br style="line-height: 25px">
</li>
</ul>
</font>
<p><font face="arial" color="#3e74d7" size="3" style="line-height: 25px">
<b style="line-height: 25px">Application Contents集合<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Contents </b></font>集合包含所有透过某个指令档加到应用程式中的项目。您可以用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Contents </b></font>集合来得到一个已经被指定为全域应用程式的项目清单。用<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Remove </b></font>和<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> RemoveAll </b></font>方法可以从这个集合中删除这些项目。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">语法<br style="line-height: 25px">
</b></font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px">Application.Contents (Key)</pre>
</font>
</div>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">参数<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Key </b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
指定检索的项目名称。</font></p>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">方法<br style="line-height: 25px">
</b></font></p>
<center style="line-height: 25px">
<table border="1" style="line-height: 25px">
<tbody style="line-height: 25px">
<tr style="line-height: 25px">
<td style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Contents.Remove </b></font></td>
<td style="line-height: 25px"><font size="2" style="line-height: 25px">
从集合中删除一个项目。</font></td>
</tr>
<tr style="line-height: 25px">
<td style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Contents.RemoveAll </b></font></td>
<td style="line-height: 25px"><font size="2" style="line-height: 25px">
从集合中删除全部项目。</font></td>
</tr>
</table>
</center>
<p><font face="arial" color="#3e76d7" size="2" style="line-height: 25px">
<b style="line-height: 25px">注解<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> Application.Content </b></font>s集合包含那些在全域中宣告但没有使用
<OBJECT> 标记的项目。它既包括<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Server.CreateObject </b></font>建立的物件,也包括<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>宣告建立的变数。例如,在下面的指令档中,strHello和objCustom都是Application.Contents集合中的元素:</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><%
Application ("strHello") = "Hello"
Set Application ("objCustom" = Server.CreateObject ("myComponent")
% ></pre>
</font>
</div>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
Application.Contents集合支援For...Each和For...Next回圈。下面的指令档说明了每一种透过Application.Contents的方法:</font></p>
<div style="line-height: 25px; background-color: #d7d7d7">
<font face="Arial" size="3" style="line-height: 25px">
<pre style="line-height: 25px"><%
Application ("strText1" = "1234567890"
Application ("strText2" = "ABCDEFGHIJ"
Application ("strText3" = "A1B2C3D4E5"
%>
<%
For Each Key in Application.Contents
Response.Write Key + "= "+ Application(Key) +"<BR>"
Next
%>
<%
For intItem = 1 to Application.Contents.Count
Response.Write CStr(intItem ) + "="
Response.Write Application.Contents(intItem ) + "<BR>"
Next
%></pre>
</font>
</div>
<p><font face="arial" color="#3e74d7" size="3" style="line-height: 25px">
<b style="line-height: 25px">Application StaticObjects集合<br style="line-height: 25px">
</b></font></p>
<p><font face="arial" color="#000000" size="2" style="line-height: 25px">
<font face="arial" color="#3e80d7" size="2" style="line-height: 25px">
<b style="line-height: 25px"> StaticObjects </b></font>集合包含所有在<font face="arial" color="#3e80d7" size="2" style="line-height: 25px"><b style="line-height: 25px"> Application </b></font>物件领域内使用
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -