ExecScriptFast()

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecScriptFast()

Post by Karl-Heinz »

The new script compiler looks very promising !

The only problem i´ve noticed so far is that Type() always returns "U" if "LPARAMETERS" is used in the script. There´s no such problem if "PARAMETERS" is used instead.

That´s the output of the attached XSharpFoxProScript.viaef

Code: Select all

PARAMETERS a,b,c
? VarType (a), VarType ( b ), VarType(c)
? Valtype (a), Valtype ( b ), Valtype(c)
? Type ('a'), Type ( 'b' ), Type('c') // comment1 ...
? Substr ('aaaxxxaaa' , 4 , 3 ) && comment2 ...
RETURN SubStr(a,b,c)

C N N
C N N
C N N
xxx
Str

LPARAMETERS a,b,c
? VarType (a), VarType ( b ), VarType(c)
? Valtype (a), Valtype ( b ), Valtype(c)
? Type ('a'), Type ( 'b' ), Type('c') // comment1 ...
? Substr ('aaaxxxaaa' , 4 , 3 ) && comment2 ...
RETURN SubStr(a,b,c)

C N N
C N N
U U U  <--------------- should show C N N
xxx
Str

PARAMETERtest C N N
LPARAMETERtest C N N
regards
Karl-Heinz
Attachments

[The extension viaef has been deactivated and can no longer be displayed.]

Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecScriptFast()

Post by Karl-Heinz »

Guys,

This script uses DB commands. Simply add the sources to the previously posted viaef.

Code: Select all

	cTest := String.Join(e"n",<STRING>{; 
	"#INCLUDE 'DBCmd.xh'",; 
	"#INCLUDE 'FoxProCmd.xh'",;
	"PRIVATE lRet" ,;
	"lRet := true" ,;
	"" ,;
	"USE D:testsmall.dbf" ,;
	"IF Used()",;
	"?  'Selected area:' , Select()" ,;
	"?" ,;
	"   SET ORDER TO 1" ,;
	"   SCAN    && FOR small->LAST < 'U'" ,;         
	"     ? small->LAST",; 
	"   ENDSCAN",; 
	"   CLOSE" ,;	
	"ELSE" ,;
	"   lRet := false" ,;
	"ENDIF",; 
	"?" ,;
	"RETURN lRet" })	    
	    
	?
	? cTest
	? 
	        
	? "Script result:" , ExecScriptFast ( cTest )   	          
	?
The script tries to do the same as this code does

Code: Select all

	USE D:testsmall.dbf 
	IF Used()
		SET ORDER TO 1
		SCAN FOR a->LAST < 'U'         
			? a->LAST 
		ENDSCAN
		CLOSE    
	ENDIF
The Scripting problems i found:

- Using the 'a->' alias fails.
- the SCAN FOR condition fails.
- The ":=" assignment must be used.

Before you run the code make sure to adjust the currently used "D:TEST" folder. Attached are the required
small.dbf and small.cdx

Note: I forgot to mention in my previous post that I´m using the 2.8c build !

regards
Karl-Heinz
Attachments
smalldbf.zip
(1.1 KiB) Downloaded 107 times
User avatar
robert
Posts: 4519
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ExecScriptFast()

Post by robert »

Karl Heinz,
Thanks for the feedback.
I'll discuss it with Nikos and we'll look into the issues.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecScriptFast()

Post by Karl-Heinz »

Robert,

i don´t know what currently is supported or not, but here are some more test:

Code: Select all

cTest := String.Join(e"n",<STRING>{;
	"#INCLUDE 'XSharpDefs.xh'" ,; 
	"&&   #INCLUDE 'Set.xh'",;	
	"" ,; 
	"SET CENTURY OFF" ,;
	"? Today()" ,;
	"SET EPOCH TO 1980" ,;
	"? SetEpoch()" ,;
	"" ,;
	"RDDInfo ( Set.AutoOpen , true )",; 
	"? 'AutoOpen' , RDDInfo ( Set.AutoOpen )" ,; 
	"RDDInfo ( Set.AutoOrder , 1 )",;
	"? 'AutoOrder' , RDDInfo ( Set.AutoOrder )" ,;
	"?" ,;
	"&&    SET DATE GERMAN" ,;
	"&&    RDDInfo ( _SET_AUTOOPEN, true )" ,;  
	"RETURN true" })	    
	    
	?
	? cTest
	? 
	        
	? "Script result:" , ExecScriptFast ( cTest )   	          
	?	


what´s not working is e.g. something like

Code: Select all

SET DATE GERMAN
RDDInfo ( _SET_AUTOOPEN, true )
I also noticed that if the script contains 'RETURN', a value must be returned, otherwise a null reference exception is thrown.

regards
Karl-Heinz
User avatar
robert
Posts: 4519
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ExecScriptFast()

Post by robert »

Karl-Heinz,
I will look into this to see what the problem is. I think the SCAN FOR problem is caused by the same problem that Juan reported for DbEval().
Can you create a Github ticket for this, so it does not get forgotten ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecScriptFast()

Post by Karl-Heinz »

robert wrote:Karl-Heinz,
I will look into this to see what the problem is. I think the SCAN FOR problem is caused by the same problem that Juan reported for DbEval().
Can you create a Github ticket for this, so it does not get forgotten ?

Robert
Robert,

it´s already logged

https://www.xsharp.eu/forum/public-vfp/ ... test#19309

In the meantime Chris added another DBEval() sample to the mentioned Github ticket.

regards
Karl-Heinz
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

ExecScriptFast()

Post by Karl-Heinz »

some more samples ...

- the first script catches a divide by zero exception.

- the seconds script enforces a Macrocompiler error because i´m trying to assign a string to the local 'lOk' which is declared as logic. Use the

"PRIVATE lOk" ,;

declaration instead and you can assign to 'lOk' whatever you like ;-)

Code: Select all

cTest := String.Join(e"n",<STRING>{;
	"#INCLUDE 'XSharpDefs.xh'" ,;
	"LOCAL lOk" ,;
	"local n as int" ,;
	"n := 0",;
	"lOk := true" ,; 
	"TRY" ,;
	"?  'Try division 12/'+ntrim(n)" ,;
	"?  'Result is:' , 12 / n" ,;
	"CATCH e AS Exception",;
	"?   e , ' happened'" ,;
	"    lOk := false" ,;
	"END TRY" ,;
	"?" ,;  
	"RETURN lOk" })
	    
	?
	? cTest
	? 
	        
	? "Script result:" , ExecScriptFast ( cTest )   	          
	?
	
        
cTest := String.Join(e"n",<STRING>{;
	"#INCLUDE 'XSharpDefs.xh'" ,;
	"LOCAL lOk as logic" ,;
	"&&  PRIVATE lOk" ,;
	"If true" ,;
	"  lOk := 'text'",;
	"else" ,; 
	"  lOk := false",;
	"endif" ,; 
	"?",;
	"RETURN lOk" })
	
	?
	? cTest
	? 
	        
	? "Script result:" , ExecScriptFast ( cTest )   	          
	?	 
		


I am impressed what´s already possible with the new script compiler !

regards
Karl-Heinz
Post Reply