FastScript is a simple script language able to handle 4 different syntax types. JScript, C++, Pascal and Basic.
Declare variables
You can declare variables using the following types.
Byte,Word,Integer | Integer type
Longint,Cardinal,TColor | Integer type
Char | Character type
Boolean | Boolean type
Real,Single,Double,Extended | Extended type
TDate,TTime,TDateTime | Extended type
String, Variant,
Pointer,WideString | Variant type
Array | Array type
C++Script maps some types to standard types:
int, long = Integer
void = Integer
bool = Boolean
float = Extended
JScript doesn't have types. Just type
var a = 10;
var s = "string";
Characters and Chr(), Ord()
The character type can hold a Unicode value (0x0000 - 0xFFFF).
To assign a variable you can do the following:
char ch = "A";
You can also give the character variable a value from a string:
string s = "Hello!";
char ch = s[1]; // ch now contains the character "H".
The character type can be used in several ways, e.g. in a condition statement.
if (ch == "A") { ... };
if (Ord(ch) == 65) { ... };
if (ch == Chr(65)) { ... };
Ord() converts a character, given as a string, to an integer value.
Chr() converts an integer value to a character, given as a string.
Strings
Strings inside quotes are always UTF16 encoded Unicode strings.
String is a Unicode string type where memory is allocated by the internal memory manager, which is very fast.
WideString is an older string type. Memory is alocated by Windows and may therefor be slower than the Unicode string type.
The first character in the string always start at position one and the last position is the same as the length of the string (s[1] ... s[length]).
Examples
String su = "Hello world!"
String sa = "Hello world, Привет мир, Hej världen...";
WideString ws = "Hello world, Привет мир...";
String s;
var str = "Hello world!";
var s;
var str: string;
begin
str := 'Hello world!';
end;
dim s as String
s = "Hello world!"
Arrays
You can create arrays of any type supported as variable.
var numbers: array[100] of Integer;
var names: array[1..10] of string;
dim numbers[100] as Integer
Default objects
There are several default objects already created. Some of them are:
Document, MainApp and ScriptUtils.
Each object contain properties and functions.
The Document object allows you access to the current document. You can move the text cursor, select text, retrieve lines, selection...
The MainApp object gives you access to some application wide functions like Open or Save file...
The ScriptUtil object contain some useful string functions.
Each object is described in detail in other help topics.
Functions and classes
There are several builtin function and classes you can use in a script.
Examples (convert an integer to a string)
string s = IntToStr(200);
var s: string;
s := IntToStr(200);
dim s as String
s = IntToStr(200)
To use classes you first have to create an object.
TForm f;
f = new TForm(nil);
f.Caption = "Test it!";
f.BorderStyle = bsDialog;
f.Position = poScreenCenter;
f.ShowModal;
var f;
f = new TForm(nil);
f.Caption = "Test it!";
f.BorderStyle = bsDialog;
f.Position = poScreenCenter;
f.ShowModal;
var f: TForm;
f := new TForm(nil);
f.Caption := 'Test it!';
f.BorderStyle := bsDialog;
f.Position := poScreenCenter;
f.ShowModal;
dim f
f = new TForm(nil)
f.Caption = "Test it!"
f.BorderStyle = bsDialog
f.Position = poScreenCenter
f.ShowModal
A few examples:
C++
.................................................................................................................................
void Hello(int n) {
string s = "Hello world!";
for (int i=0; i < n; i++) {
ShowMessage(s + " " + IntToStr(i));
}
}
{
// Call the Hello() function and show the message
// two times.
Hello(2);
}
.................................................................................................................................
JScript
.................................................................................................................................
function Hello(n) {
var s = "Hello world!";
for (i=0; i < n; i++) {
ShowMessage(s + " " + IntToStr(i));
}
}
{
// Call the Hello() function and show the message
// two times.
Hello(2);
}
.................................................................................................................................
Pascal
.................................................................................................................................
procedure Hello(const n: Integer);
var
s: string;
i: Integer;
begin
s = 'Hello world!';
for i := 0 to n - 1 do
ShowMessage(s + ' ' + IntToStr(i));
end;
begin
// Call the Hello() function and show the message
// two times.
Hello(2);
end.
.................................................................................................................................
Basic
.................................................................................................................................
sub Hello(n as Integer) {
dim s as String
dim i as Integer
s = "Hello world!"
for i = 0 to n - 1
ShowMessage(s + " " + IntToStr(i))
next
end sub
' Call the Hello() function and show the message
' two times.
Hello(2)
.................................................................................................................................
|