Harbour For Android HTML Form Demo

Issues and Discussions related to Harbour

Moderator: Rathinagiri

Post Reply
User avatar
Roberto Lopez
HMG Founder
Posts: 4004
Joined: Wed Jul 30, 2008 6:43 pm

Harbour For Android HTML Form Demo

Post by Roberto Lopez »

Hi All,

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

Regards,

Roberto.
Regards/Saludos,

Roberto


(Veritas Filia Temporis)
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Harbour For Android HTML Form Demo

Post by Rathinagiri »

Nice implementation Roberto.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Harbour For Android HTML Form Demo

Post by serge_girard »

Thanks Roberto !

Serge
There's nothing you can do that can't be done...
JALMAG
Posts: 262
Joined: Sun Jan 10, 2010 7:05 pm
DBs Used: DBF, MariaDB
Location: España - Spain

Re: Harbour For Android HTML Form Demo

Post by JALMAG »

¡Gracias!
Post Reply