I've created a simple demo, showing how to create an HTML form to enter a value and send it to a Harbour function to be processed.I hope that it be useful.
Code: Select all
/*
H4A v5 HTML Demo (Based on original HTML Demo by Alexander Kresin)
This demo creates a simple form that allows to the user to enter a string a process it
via a Harbour function.
How to test:
Rename the h4a demo (testhrb.prg) as testhrb.bak, then, create a new testhrb.prg file,
containing this and build the apk following the usual procedure.
How it works:
- A string called 'sRet' is filled with HTML + JavaScript code, enough to generate
a page containing a textbox, a button and a paragraph. This string is sent to
Android's webview to be rendered.
- When the button is clicked, the JavaScript function 'MyFuncCall' is executed.
This function gets the textbox value and stores it in the 'first' variable, then,
it invokes Harbour function 'MyFunc' using as parameter the content of 'first' via
'jProxy.get'. The returned value is stored in the variable 'response'.
- Finally, the paragraph 'p1' is filled with the content of 'response'.
- In order to simplify the code, I've ommited the error checking on 'jProxy'. Please
look at the original HTML demo for proper usage.
*/
FUNCTION FModList()
RETURN "Select Item:" + Chr(13)+Chr(10) + Chr(13)+Chr(10) + ;
" **Html test**" + Chr(13)+Chr(10)
FUNCTION FModExec( iMod )
IF iMod == 1
RETURN HtmlTest()
ENDIF
RETURN "Unknown module"
FUNCTION HtmlTest()
LOCAL sRet
sRet := '<html>' + ;
'<head>' + ;
'<script type="text/javascript"> ' + ;
'function MyFuncCall()' + ;
'{' + ;
'first = document.getElementById("fname").value ; ' + ;
'response = jProxy.get("MyFunc([" + first + "])" ) ;' + ;
'document.getElementById("p1").innerHTML = response; ' + ;
'}' + ;
'</script>' + ;
'</head>' + ;
'<body>' + ;
'First Name:' + ;
'<br>' + ;
'<input type="text" id="fname"> ' + ;
'<br>' + ;
'<input type="submit" value="Execute Harbour Code" onclick="MyFuncCall();">' + ;
'<p id="p1"></p>' + ;
'</body>' + ;
'</html>'
RETURN sRet
FUNCTION MyFunc( cString )
LOCAL cRes
cRes := 'Your first name is: ' + ALLTRIM(UPPER(cString)) + ' !!!'
RETURN cRes
Roberto.