Show/Hide Toolbars

XSharp

XSharp 2.8 adds support for Runtime scripting through the ExecScript() function.

Scripting was added for the FoxPro dialect but also works for other dialects.

Inside scripts you will have the full X# language at your disposal.

The first time a script runs it will be compiled. If you run the same script a second time then the script compiler can reuse the already compiled version of the first script.

 

An example (FoxPro dialect, MessageBox() is a FoxPro functon)

 

VAR cScript := 'MessageBox("Hello ExecScript")'
ExecScript(cScript)

Of course scripts can also be multiple lines and can call any function in the runtime and in your code.

PUBLIC and PRIVATE variables that are visible when your script is started are accessible by the script.

You can also declare new local variables in the script and use any statement and user defined command that you would normally use.

 

We did an online session about scripting in Jan 2021 that shows several example scripts. See https://www.youtube.com/watch?v=88crZsEiAOg&t=5s for the recording.

One sample script from that demo is

 

LPARAMETERS oForm
USE employees.dbf
PrintOut(oForm, 'private',MyPrivate, Used(), Alias())
GO TOP
DO WHILE ! Eof()  
  PrintOut(oForm, RecNo(), FieldGet(1), FieldGet(2), FieldGet(3))      
  SKIP
ENDDO  
USE  

That script calls a PrintOut function and passes it the form that was received as parameter. The PrintOut function then adds a line of text to the terminal window that was passed to the script. The USE, GO TOP and SKIP commands are all UDCs that are handled by the script compiler without problems.