TScript |
||||
Homepage TScript Syntax TScript Usage Built-In Functions TFunc Declaration TFunc Body Overloading External Variables Tech Talk Version History FAQ/Credits |
New
version 1.6 of TScript is available: script16.zip
TScript is a Delphi component. It includes an interpreter for a Delphi-pascal like script language. You can use this component for:
The script interpreter consists of three components:
The language of Script uses the basic elements of the delphi language. Begin-End, If-Then-Else, For, While, Repeat-Until are the possible control structures. Operators: Assignment, +, - , *, / div, mod, not. Procedure calls, Constants as usual. In Script you don't need to define the type of a variable. An example: {Calls the procedure print twice} i := 2; while i > 0 do begin i := i - 1; Print (i); end; The procedure Print is an user defined function. Adding user defined functions to Script is very simple. Just add a TFunc component to your form. The property Declaration of the TFunc component determines the name and the parameters of the function. The declaration of the function Print looks like this: print (all) "all" stands for every possible datatype. If the function Print is called, the event "OnEval" is fired. TOnEvalEvent = procedure (Sender : TObject; args : TArgList; var Result : Variant) of Object; The parameter args contains the arguments of the function and res stores the return value (if there is one). A possible implementation of the function Print is: procedure TForm1.fncPrintEval; begin ListBox1.Items.Add (VarToStr (args[0].Eval)); end; "args[0].Eval" returns a variant that hold the value of the first and only argument. All variables and constants use the Delphi datatype variant to store values. A user defined function is assigned to a TFuncs component and not directly to the TScript component. Doing this, the set of functions accessible in the TScript component can be used by more than one TScript components and can be changed during runtime. |