Basic function call don't work why ?

Feb 4, 2012 at 2:55 AM

Here the code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
say <%= SayHello()%><br>
</body>
</html><%
FUNCTION SayHello
  RETURN "Hello World"
ENDFUNC%>

Coordinator
Feb 4, 2012 at 11:43 AM
Edited Feb 4, 2012 at 11:43 AM

There seems to be an issue with the FUNCTION statement in the MergeScript method in activevfp.prg (in the source) .   I'm looking at this and hopefully there will be a fix to give some more flexibility for Function libraries w/ExecScript and scripting in general.

Coordinator
Feb 4, 2012 at 12:26 PM

In the meantime, something like this works:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
say <%= EXECSCRIPT(FILETOSTR(oProp.AppStartPath+'\prg\sayhello.prg')) %><br>
</body>
</html>

-------

* sayhello.prg

*     NOTE: external program file = 1 function and can be re-used by multiple files)

RETURN "Hello World"

Coordinator
Feb 4, 2012 at 5:05 PM
Edited Feb 4, 2012 at 6:01 PM

Here's a solution to using a Function Library without locking files (preventing on the fly changes):

1.)  In main.prg add a new CASE statement:

CASE oProp.Action=='test'
        lcHTMLout=ExecScript(FILETOSTR(oProp.AppStartPath+'\prg\main2.prg'))

2.) 

*main2.prg
*just add this section to existing function libs and you're good to go

lcHTMLout= FILETOSTR(oProp.HtmlPath+'test2.avfp')
lcHTMLout= oHTML.mergescript(lcHTMLout)

RETURN lcHTMLout

************************************************************************
*
***FUNCTIONS******************
function hello
RETURN "Hello Worlds"
endfunc
function timenow
RETURN STR(time())
endfunc

*

3.) test2.avfp

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<br>
say <%=hello()%>
</body>
</html>

 

works!!!!!!!!!!!!!!!!!!!

Coordinator
Feb 4, 2012 at 6:00 PM

Or just add new functions to the bottom of main.prg, of course, if you don't want a totally separate function file like above...