|
|
A ScriptingContext example
|
The following is Visual Basic code for a simple component :
Public mySC As ScriptingContext
Public noteText As String
Public objectName As String
' --------------------
Public Sub OnStartPage(objScriptContext As ScriptingContext)
Set mySC = objScriptContext
MakeAnote ("in OnStartPage")
End Sub
' ------------------
Public Sub OnEndPage()
MakeAnote ("in OnEndPage")
End Sub
' ------------------
Public Sub setMyName(myName As String)
objectName = myName
MakeAnote ("Name of this object set")
End Sub
' ---------------
Public Sub myTest()
MakeAnote ("in myTest")
Set rp = mySC.Response
rp.Write noteText
End Sub
' -------------------
Private Sub MakeAnote(msg As String)
' append to text file
Set fso = CreateObject("Scripting.FileSystemObject")
Set fp = fso.OpenTextFile("c:\phdlog.txt", 8)
noteText = noteText + "<BR>[ " + objectName + " ] "
noteText = noteText + msg + vbCrLf
fp.WriteLine "[" + objectName + "]" + msg
fp.Close
End Sub
|
A Session object is created in global.asp :
<%
SUB Session_OnStart
objPath = Server.MapPath( "phdTest.dll")
Server.RegisterObject( objPath)
SET Session( "myObj") = Server.CreateObject("phdTest.testObject")
Session( "myObj").setMyName( "Session Object")
END SUB
%>
|
Some VBScript to exercise this component is :
<%
objPath = Server.MapPath( "phdTest.dll")
Server.RegisterObject( objPath)
set testObj = Server.CreateObject( "phdTest.testObject")
testObj.setMyName( "testObj")
testObj.myTest
Session( "myObj").myTest
%>
|
The output to the logfile c:\phdlog.txt from calling the script TWICE
and then terminating Dynamic-CD is :
[]in OnStartPage
[Session Object]Name of this object set
[]in OnStartPage
[testObj]Name of this object set
[testObj]in myTest
[Session Object]in myTest
[testObj]in OnEndPage
[]in OnStartPage
[testObj]Name of this object set
[testObj]in myTest
[Session Object]in myTest
[testObj]in OnEndPage
[Session Object]in OnEndPage
|
|