Contents コレクションには、スクリプト コマンドによってアプリケーションに追加された項目すべてが含まれます。Contents コレクションを使用すると、アプリケーション スコープが与えられている項目の一覧を取得したり、特定の項目を操作の対象に指定したりすることができます。また、Remove メソッドと RemoveAll メソッドを使用して、コレクションから項目を削除することもできます。
Application.Contents( Key )
Contents.Remove | コレクションから項目を削除します。 |
Contents.RemoveAll | コレクションからすべての項目を削除します。 |
Application.Contents コレクションに含まれるのは、<OBJECT> タグを使わずにアプリケーション レベルで宣言された項目です。これには、Server.CreateObject を使用して作成されたオブジェクトと、Application 宣言で作成されたスカラ変数の両方が含まれます。たとえば、次のスクリプトでは、strHello
と objCustom の両方が Application.Contents コレクションのメンバになります。
<%
Application("strHello") = "Hello"
Set Application("objCustom") = Server.CreateObject("MyComponent") %>
Application.Contents コレクションでは、For...Each と For...Next のループを使用できます。次の 2 つのスクリプトは、Application.Contents コレクションに対し、これらの方法を使用して繰り返し処理を行う例です。
<%
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
%>
Application.Contents コレクションを使用したサンプル .asp ファイルは、Platform SDK の IIS セクションにある ASP Samples または MSDN Online - Internet Information Services にあります。