executeSilent

Syntax

executeSilent(SourceCode:string [,Parameter, ...])

The function executeSilent receives a string and interprets it as though it were the source code of a method.

The function executeSilent accepts all statements. The anonymous identifier ? refers to the Method object that called the executeSilent function. The anonymous identifier @ is received by the calling method.

The semantics of executeSilent is as follows:

  • When the string method does not have a return value, executeSilent returns VOID.

    Example

    var objPath : string := "Track"
    var attrName: string := "Length"
    var attrVal : length := 3.5
    executeSilent(to_str(objPath, ".", attrName, ":=", attrVal))
  • When the string method has a return value, these may look as follows:

    • When the string method contains a syntax error, executeSilent returns VOID.

      Example

      executeSilent("-> integer; 1+") -- returns VOID 
    • When a runtime error occurs while the string method is executed, executeSilent returns the default value of the corresponding type, i.e., the value of a local variable of this type would have at the beginning of the execution of the method. Note that Plant Simulation does not open the Debugger when a runtime error occurs, but continues to be executed. Use the function execute to make Plant Simulation open the Debugger, when runtime errors occur. For example, the executeSilent-statement below returns false because assigning the keyword "if" to the name of an object causes a runtime error.

      Example

      executeSilent("->boolean; Station.name := \"if\"; return true")
      -- returns false because of a runtime error 
  • In all other cases, executeSilent will return the return value of the string method.

    Example

    executeSilent("->integer; return := 42") -- returns 42

The function executeSilent executes the referenced Method. You can use it to execute methods that you referenced via variables. Let us say you save a method to a variable obj of data type object, you can now call this method using obj.executeSilent.

Example

param obj: object, new_name: string
if not executeSilent("param o: object -> boolean; o.name := \"" + new_name + "\"; return true" obj) 
   print "invalid name"
end 

Be aware that the variant

executeSilent("->boolean; " + obj + ".name := \"" + new_name + "\"; return true") 

does not work, when obj points to a method.

Note:

The syntax which is used in the argument for the executeSilent function has to be the same as the Method syntax which calls the executeSilent function.

Related Topic

execute