TScript

External Variables

Homepage
TScript
External Variables
 

Global Variables and Constants

Global variables and constants are valid in all scripts you compile. Assumed you're using color constants in all of your scripts:

const red = $FF0000;
const green = $00FF00;
const blue = $00007F;

line (0, 0, 10, 10, blue);
....

In this case it's advisable to use global constants instead of adding the constant declarations above to each script. Add the following lines to the initialization section of your Delphi form:

script1.setGlobalConst ('red', $FF0000);
script1.setGlobalConst ('green', $00FF00);
script1.setGlobalConst ('blue', $00007F);

Global Variables can be used to transfer data from one script to another. You could store information about the environment in global variables.

Finding Variables and Constants

You can find variables and constants by specifying their name or by a numerical index. The following functions all return a TDataItem object in success.

GetGlobal (nam : string) : TDataItem;
Returns the global variable or constant with name "nam". If there is no dataitem with this name this function returns nil.

GetGlobalIndex (i : Integer) : TDataItem;
Returns the global variable or constant with index "i". If you specify a bad index an exception occurrs. Valid indizes are [0..script1.GlobalCount - 1]

GetVar (nam : string) : TDataItem;
Returns the variable or constant with name "nam". If there is no dataitem with this name this function returns nil.

GetVarIndex (i : Integer) : TDataItem;
Returns the variable or constant with index "i". If you specify a bad index an exception occurrs. Valid indizes are [0..script1.ItemCount - 1]

Deleting Global Variables and Constants

DeleteGlobal (nam : string);
Deletes the global variable or constant with name "nam".

DeleteGlobals;
Deletes all global variables and constants.

The Method SetVar

To create variables in OnEval events use the method SetVar of the TScript component. It only makes sense to call this method if a script is running.