Basic Syntax "MAIN" problem

As described on page 89 in the actual documentation, I tried to return a value using the Basic syntax, but it does not work for me.

I am using the newest version of TMS Scripter components in Delphi 2007.

Using the Pascal syntax as described works fine for me, but in the Basic syntax (as described in documentation on page 89), it does not:
MAIN = (10+6)/4
results in: "Syntax error. Source position: 1,6

Issue in documentation (?):

(*) In Basic syntax, to return a function value you must use "FunctionName =
Value" syntax. You can also return values in basic without declaring a function.
In this case, use the reserved word "MAIN" : "MAIN = (10+6)/4".

It works fine here, the following Delphi project runs fine. Please provide a project with steps to reproduce the issue.

program Project3;

{$APPTYPE CONSOLE}

uses
  System.SysUtils, atScript, atScripter;

var
  Scripter: TatScripter;
begin
  DefaultMachineClass := TBaseScripterMachine;
  Scripter := TatScripter.Create(nil);
  Scripter.CurrentScript := Scripter.AddScript(slBasic);
  Scripter.SourceCode.Text := 'MAIN = (10+6)/4';
  WriteLn(Scripter.Execute);
  ReadLn;
  Scripter.Free;
end.

My code is ("aStrList" contains the code to execute):

  var
    vResult : Variant;
  begin
    if( bVBScript )
    then atScripter.DefaultLanguage := slBasic
    else atScripter.DefaultLanguage := slPascal;

    try
      atScripter.SourceCode := aStrList;
      atScripter.Compile;
      if( atScripter.Compiled )
      then vResult := atScripter.Execute;
      ...
    except
      on E:Exception do
        begin
        if( bShowMessages )
        then ICCMod_MainForm.ErrorMessage( E.Message );
        end; // of E:
    end; // of except
end;

Changing the DefaultLanguage will affect the new scripts you create. It won't change language of existing scripts. You have to create a new script to benefit from it:

    if( bVBScript )
    then atScripter.DefaultLanguage := slBasic
    else atScripter.DefaultLanguage := slPascal;
    Scripter.Scripts.Clear;  
    Scripter.CurrentScript := Scripter.Scripts.Add;
    // proceed
1 Like

Thanks a lot. Now it works as exspected. :hugs:

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.