TMS Scripter - Accessing script variables

I'm trying to add a scripting capabilty to my C++ Builder Windows app that will allow users to create and run scripts written in Basic. I'm using C++ Builder R12 and TMS Scripter v7.36. I am new to Scripter and have rudimentary knowledge of Delphi but have been using C++ Builder since R1.

I provide the user interface - the scripts do not need to create their own forms. TatBasicScripter appears to be adequate for what I need & I have everything working well except for watchlists. Users can single-step etc but I haven't been able to figure out how to access variables defined in the user's script. There's a sample program in the demo folder ...demos\basic\debugger that refers to a watchlist but doesn't seem to actually implement one.

The scripter manual states that user vars defined with a "DIM" statement will be considered global. I'm using OptionExplicit = true which then requires that declaration.

I tried using IDEEngine along with the IDEWatchList component but that doesn't like tying into TatBasicScripter. And attempts to use a script component other than TatBasicScripter fail to accept a script in Basic. I saw an older reference to that issue but the suggested workaround didn't work.

I also tried the ScriptInfo->Variables and ScriptInfo->Globals properties.

I've looked through everything I could think of for an example of accessing a script variable from the "host" program and found a few suggestions but all seemed to refer to earlier versions of Scripter. I'm sure I'm missing something obvious here.

Does anyone have an example of accessing:

  1. The count of script variables
  2. The var names
  3. The var contents
    ?

Thank you!
John C

Hello @Coelho_John, welcome to TMS Support Center!

Correct. You should be using TIDEScripter for that, which I recommend, thus you can use the Scripter IDE and all the features that come with it, including watch list.

If they are declared above all the declaration of all sub functions.

In this case you should explicitly tell the component you are using Basic language, by clearing all scripts and then adding a new script in Basic syntax.

Maybe you can provide a simple example of a script and the code you are trying to use, is there a chance your script variables are not global?

Are you able, for example, to access the list of functions declared in the script?

Thank you for the response. I will try using TIDEScripter again and will respond again when I have some results. I am using about 25 methods of my own via Script->DefineMethod, so my Basic-language examples don't look too much like typical Basic programs.

John C

I wrote up a simple example of my trying to use a script written in Basic that uses TIDEScripter. The code:

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "atScript"
#pragma link "atScripter"
#pragma link "IDEMain"
#pragma link "ScrMemo"
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  Script1->DefaultLanguage = slBasic;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Script1->OptionExplicit = true;
  Script1->SourceCode = IDEMemo1->Lines;
  Script1->Execute();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Script1CompileError(TObject *Sender, UnicodeString &msg, int row,
          int col, bool &ShowException)
{
  ShowMessage("Line " + IntToStr(row) + " Column " + IntToStr(col) + " " + msg);
  ShowException = false;
}
//---------------------------------------------------------------------------
/*   *********************(From the dfm file)*************************
 object Script1: TIDEScripter
    DefaultLanguage = slBasic
    SaveCompiledCode = False
    EventSupport = False
    OnCompileError = Script1CompileError
    ShortBooleanEval = True
    LibOptions.SearchPath.Strings = (
      '$(CURDIR)'
      '$(APPDIR)')
    LibOptions.UseScriptFiles = False
    CallExecHookEvent = False
    Left = 392
    Top = 56
  end

The Basic script is:
DIM A
DIM B
A = 1
B = 5
A = A + B
ShowMessage(A)

Scripter reports a syntax error on the first '=' character. If I replace that with := then the error moves ot the next line. This leads me to believe that the script is being interpreted as a Delphi program. i suspect I'm missing something simple here.

(I looked through the samples but all
of the samples showing scripts written in Basic use TatBasicScripter).

Thank you again for your help.

Please refer to:

In summary you should use;

  Script1->DefaultLanguage = slBasic;
  Script1->Scripts->Clear;
  Script1->CurrentScript = Script1.Scripts.Add;

Thank you Wagner. That resolved my issue.

John C

1 Like

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