PPJ Manual
HomeCurrent IssuesDownloads
  • Welcome
  • Releases
    • PPJ 2023
  • PPJ 2023
  • PPJ Web API
  • PPJ Desktop API
  • Wisej.NET Documentation
  • General
    • Framework
      • Features
        • SAL and SQL Functions
        • Constants and Variables
        • SalContext
        • Visual Toolchest
        • XSal2
        • Reporting Support
        • LINQ Support
        • SalCompileAndEvaluate
        • Unicode Support
        • Startup Arguments
        • App.config
      • Data Types
        • Automatic Casts
        • Dynamic Arrays
      • Controls
        • ToolBar
        • TabControl
        • TableWindow
        • QuickObject
        • Ribbon Bar
        • NavigationBar
      • SQL Support
        • Configuration
        • ADO.NET Drivers
        • Bind and Into Variables
        • DBP Parameters
        • SqlContext
      • Extensions
        • Table Window
        • Unicode Support
        • Bug Fixes
        • Object Oriented Types
        • Custom Parsers
        • Named Properties
        • Microsoft Charts
        • Tabbed MDI
        • Watermark
        • HTML Rendering
      • Skins and Themes
        • Skin Files
        • Theme Files
        • Configuration
        • Skin Editor
        • Theme Builder
      • Tracing
        • Trace Viewer
        • Default Listeners
        • Tracing the Application
      • Spell Checker
        • Dictionaries
    • Ported Application
      • Project Structure
        • Late Bind Calls
        • Visual Styles
        • Unqualified References
        • Message Actions
        • When SQLError
        • Classes
      • Global Items
      • Forms
      • COM/ActiveX
      • Multiple Inheritance
      • Configuration Tool
      • Issues & Workarounds
    • Ported Reports
      • General
      • Crystal Reports
        • Structure
        • Unsupported Features
      • List & Label
        • Report Conversion
        • Structure
        • Document
        • Input Items
        • Passing Data
        • Unsupported Features
      • Reporting Services
        • Features
      • Stimulsoft
        • Break Groups
        • Fields
        • Formulas
        • Cache Mode
Powered by GitBook
On this page
  • Syntax
  • Full Script
  • Scope

Was this helpful?

  1. General
  2. Framework
  3. Features

SalCompileAndEvaluate

PreviousLINQ SupportNextUnicode Support

Last updated 2 years ago

Was this helpful?

SalCompileAndEvaluate uses the interpreter built in the PPJ Framework. Which is the same one used to evaluate bind/into variables in embedded SQL statements.

The preferred parser (default) supports C# syntax. However, it is possible to plug in a custom parser and support any syntax, including SAL.

See for more information on how to plug in your own parser.

Syntax

By default, the PPJ Framework supports the C# language. If the expressions being evaluated by SalCompileAndEvaluate() are simple function calls or variables access, the execution of the expression shouldn't impose any problem.

However, if the expression being evaluated contains operators that are incompatible with C# you will get a syntax error. See the following table to see the most common operators that need to be replaced.

Operator
SAL
C#

String Concatenation

||

+

Logical And

AND

&&

Logical Or

OR

||

Equality Comparison

=

==

There is an important difference when using SalCompileAndEvaluate: by default inline assignments are disabled to avoid assigning values to a variable when the intention of the expression was to compare the value for equality.

For example, in Team Developer the expression "If nValue = 10" means that the value of nValue should be compared to 10 and the result of the comparison is the result of the expression. However, in C# the single "=" operator is an assignment operator, so the expression above means that 10 should be assigned to nValue and then returned as the result of the expression.

For this reason, when executing expression with the "=" operator but not preceded by a Set keyword, SalCompileAndEvaluate() returns an error for the illegal assignment. The expression should be changed to "If nValue == 10" using the "==" equality operator.

You can enable inline assignments by setting a static property on the ScriptEngine type:

PPJ.Runtime.Script.ScriptEngine.AllowInlineAssignments = true;

Full Script

In Team Developer it was possible to only execute one statement at a time. Using the script engine in the PPJ Framework you can now execute entire scripts using the full C# language.

To run a script you need to enclose the script in a block, as shown in the example below:

Sal.CompileAndEvaluate(@"
{
  for (int i = 0; i < 10; i++)
  {
    Sal.MessageBox(i.ToString(), sTitle, 0);
  }
}", ...);

Scope

SalCompileAndEvaluate() uses the same scope resolution rules used by the Sql module in the PPJ Framework. Basically, local variables are never accessible. All globals, instance and static members are always visible. Local variables can be used in scripts only if they have been extracted into the SqlLocals inner class.

Custom Parsers