Roger,
below are little modified your examples.
I defined some next variables and added it in some next methods.
There are some problems or some for me weird behaviors with visibility
and results of each types of defined variables.
If you run echo, getTime or echoVars,
variables are inicialized and result is displayed – ok.
Now try refresh web page, e.g. with press F5 or again from main menu call this or any other method
and you will see new results:
- in contents for variables defined with clause CLASS are added new values
and in variables without that clause is still new only last one value – OK......
For this variants I see cases/options where it will be used – OK...
BUT if you at once time open this same index.html file / examples on web-browser’s next tab-page
or in new standalone instance on the same pc/notebook
or from other pc/notebook,
it works in the same way...
- when you run it, in class variables will be total count from all opened instances
and not only number, how many times it was called from that concrete web-browser window...
Please, how must be defined variables or methods, if it should start fill array or sum/add number from begin
in every new open web-brower window on the same or from other workstation?
TIA & Regards
Zdeno
Code: Select all
#INCLUDE "dcdialog.CH"
#define CRLF Chr(13)+Chr(10)
CLASS Test FROM CustomWebHandler
HIDDEN:
CLASS VAR chaTime // ClassHidden aTime
CLASS VAR chaString
CLASS VAR chnCount
VAR haTime // Hidden aTime
VAR haString
VAR hnCount
PROTECTED:
CLASS VAR cpaTime // ClassProtected aTime
CLASS VAR cpaString
CLASS VAR cpnCount
VAR paTime // Protected aTime
VAR paString
VAR pnCount
EXPORTED:
CLASS VAR ceaTime // ClassExported aTime
CLASS VAR ceaString
CLASS VAR cenCount
VAR eaTime // Exported aTime
VAR eaString
VAR enCount
EXPORTED:
METHOD echo, getTime, echoVars, crash, echoHtml, initVars
ENDCLASS
* --------
METHOD Test:InitVars()
DEFAULT ::chaTime := {}
DEFAULT ::chaString := {}
DEFAULT ::chnCount := 0
DEFAULT ::haTime := {}
DEFAULT ::haString := {}
DEFAULT ::hnCount := 0
DEFAULT ::cpaTime := {}
DEFAULT ::cpaString := {}
DEFAULT ::cpnCount := 0
DEFAULT ::paTime := {}
DEFAULT ::paString := {}
DEFAULT ::pnCount := 0
DEFAULT ::ceaTime := {}
DEFAULT ::ceaString := {}
DEFAULT ::cenCount := 0
DEFAULT ::eaTime := {}
DEFAULT ::eaString := {}
DEFAULT ::enCount := 0
RETURN self
*
METHOD Test:echo( cParamName1 )
LOCAL cHtml := ""
::setErrorBlock()
BEGIN SEQUENCE
::initVars()
AAdd( ::chaTime, Time() )
::chnCount ++
AAdd( ::haTime, Time() )
::hnCount ++
*
AAdd( ::cpaTime, Time() )
::cpnCount ++
AAdd( ::paTime, Time() )
::pnCount ++
*
AAdd( ::ceaTime, Time() )
::cenCount ++
AAdd( ::eaTime, Time() )
::enCount ++
*
cHtml += "<html><title>Test:echo() was called</title><body>"
cHtml += '<pre>'
cHtml += "Parameter cParamName1 is " + ::httpRequest:form:getCollection()[1,1] + CRLF
cHtml += DC_Array2String(::httpRequest:form:getCollection()) + CRLF
cHtml += 'Pcount is: ' + Alltrim(Str(Pcount())) + CRLF
cHtml += 'Query String is: ' + ::httpRequest:getQueryString() + '</br>' + CRLF
cHtml += '</br>'+ CRLF
cHtml += 'chaTime: ' + Var2Char( ::chnCount ) + ' - ' + Var2Char( ::chaTime ) + '</br>'+ CRLF
cHtml += 'haTime : ' + Var2Char( ::hnCount ) + ' - ' + Var2Char( ::haTime ) + '</br>'+ CRLF
cHtml += '</br>'+ CRLF
cHtml += 'cpaTime: ' + Var2Char( ::cpnCount ) + ' - ' + Var2Char( ::cpaTime ) + '</br>'+ CRLF
cHtml += 'paTime : ' + Var2Char( ::pnCount ) + ' - ' + Var2Char( ::paTime ) + '</br>'+ CRLF
cHtml += '</br>'+ CRLF
cHtml += 'ceaTime: ' + Var2Char( ::cenCount ) + ' - ' + Var2Char( ::ceaTime ) + '</br>'+ CRLF
cHtml += 'eaTime : ' + Var2Char( ::enCount ) + ' - ' + Var2Char( ::eaTime ) + '</br>'+ CRLF
cHtml += '</br>'+ CRLF
cHtml += "</pre></body></html>"
RECOVER USING cHtml
END SEQUENCE
RETURN cHtml
*
METHOD Test:echoVars()
LOCAL cResponse, aVars, i, oForm
::setErrorBlock()
BEGIN SEQUENCE
::initVars()
AAdd( ::chaTime, Time() )
::chnCount ++
AAdd( ::haTime, Time() )
::hnCount ++
*
AAdd( ::cpaTime, Time() )
::cpnCount ++
AAdd( ::paTime, Time() )
::pnCount ++
*
AAdd( ::ceaTime, Time() )
::cenCount ++
AAdd( ::eaTime, Time() )
::enCount ++
*
oForm := ::httpRequest:getForm()
aVars := oForm:getCollection()
cResponse := '<H1> Echoing all Vars </H1>'
cResponse += '<pre>' + CRLF
FOR i := 1 TO Len(aVars)
cResponse += aVars[i,1] + ' : ' + aVars[i,2] + CRLF
NEXT
cResponse += '</br>'+ CRLF
cResponse += 'chaTime: ' + Var2Char( ::chnCount ) + ' - ' + Var2Char( ::chaTime ) + '</br>'+ CRLF
cResponse += 'haTime : ' + Var2Char( ::hnCount ) + ' - ' + Var2Char( ::haTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += 'cpaTime: ' + Var2Char( ::cpnCount ) + ' - ' + Var2Char( ::cpaTime ) + '</br>'+ CRLF
cResponse += 'paTime : ' + Var2Char( ::pnCount ) + ' - ' + Var2Char( ::paTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += 'ceaTime: ' + Var2Char( ::cenCount ) + ' - ' + Var2Char( ::ceaTime ) + '</br>'+ CRLF
cResponse += 'eaTime : ' + Var2Char( ::enCount ) + ' - ' + Var2Char( ::eaTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += '</pre>'
RECOVER USING cResponse
END SEQUENCE
RETURN cResponse
* ------------
//
// The method :get() handles the RESTful path CurrentTime/get
//
METHOD Test:getTime()
LOCAL cThreadId
LOCAL cResponse := ""
cThreadId := AllTrim(Str(ThreadId()))
::setErrorBlock()
BEGIN SEQUENCE
::initVars()
AAdd( ::chaTime, Time() )
::chnCount ++
AAdd( ::haTime, Time() )
::hnCount ++
*
AAdd( ::cpaTime, Time() )
::cpnCount ++
AAdd( ::paTime, Time() )
::pnCount ++
*
AAdd( ::ceaTime, Time() )
::cenCount ++
AAdd( ::eaTime, Time() )
::enCount ++
*
cResponse += "<!DOCTYPE html>"
cResponse += "<html>"
cResponse += "<head><title>"+ProcName()+"</title></head>"
cResponse += "<body>"
cResponse += "<h1>Current Time:</h1>"
cResponse += "<p>"+Time()+" (HH:MM:SS)</p>"
cResponse += "<small>By thread: "+cThreadId+"</small>"
cResponse += '</br>'+ CRLF
cResponse += 'chaTime: ' + Var2Char( ::chnCount ) + ' - ' + Var2Char( ::chaTime ) + '</br>'+ CRLF
cResponse += 'haTime : ' + Var2Char( ::hnCount ) + ' - ' + Var2Char( ::haTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += 'cpaTime: ' + Var2Char( ::cpnCount ) + ' - ' + Var2Char( ::cpaTime ) + '</br>'+ CRLF
cResponse += 'paTime : ' + Var2Char( ::pnCount ) + ' - ' + Var2Char( ::paTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += 'ceaTime: ' + Var2Char( ::cenCount ) + ' - ' + Var2Char( ::ceaTime ) + '</br>'+ CRLF
cResponse += 'eaTime : ' + Var2Char( ::enCount ) + ' - ' + Var2Char( ::eaTime ) + '</br>'+ CRLF
cResponse += '</br>'+ CRLF
cResponse += "</body>"
cResponse += "</html>"
RECOVER USING cResponse
END SEQUENCE
RETURN cResponse
* -----------
METHOD Test:crash()
LOCAL cResponse
::setErrorBlock()
BEGIN SEQUENCE
&('CrashThisProgram()')
RECOVER USING cResponse
END SEQUENCE
RETURN cResponse
*
METHOD Test:echoHtml( cHtml )
DEFAULT cHtml := 'No Html exists'
RETURN MemoRead(cHtml)