Built-in routines
These routines are available to every script, in all languages: they belong to the System library, which is always loaded. They are called the same way in Pascal, Basic and JavaScript. The examples write strings in double quotes, as in Basic and JavaScript; in Pascal, write them in single quotes.
Applications can add other routines and libraries, and can also remove some of these routines: see the documentation of your application.
Some routines change the variables passed to them (parameters by reference, marked var in the tables): pass a variable to them, not an expression.
Strings
| Routine | Description |
|---|---|
Length(S) |
Number of characters of S (or number of items of an array). |
Copy(S, Index, Count) |
Count characters of S starting at Index (the first character is 1). Without Count, the rest of the string. |
Pos(SubStr, S) |
Position of the first occurrence of SubStr in S, or 0. |
Delete(var S, Index, Count) |
Removes Count characters of the variable S, starting at Index. |
Insert(SubStr, var S, Index) |
Inserts SubStr into the variable S at position Index. |
UpperCase(S), LowerCase(S) |
S in upper or lower case (ASCII letters only). |
AnsiUpperCase(S), AnsiLowerCase(S) |
S in upper or lower case (all letters). |
Trim(S), TrimLeft(S), TrimRight(S) |
S without leading and trailing, leading only, or trailing only spaces and control characters. |
CompareStr(S1, S2) |
Compares two strings, case-sensitive: negative if S1 < S2, 0 if equal, positive if S1 > S2. |
CompareText(S1, S2) |
Like CompareStr, not case-sensitive. |
AnsiCompareStr(S1, S2), AnsiCompareText(S1, S2) |
Like CompareStr and CompareText, following the language rules of the system. |
Format(Fmt, Args) |
Formats an array of values according to a Delphi format string: Format("%d items, %.2f each", [3, 2.5]) is "3 items, 2.50 each". |
Chr(Code) |
The character with the character code: Chr(65) is "A". |
Ord(C) |
The character code of a character (the first character of a string): Ord("A") is 65. |
IsValidIdent(S) |
True if S is a valid identifier. |
Copy("Hello", 2, 3) -> "ell"
Pos("lo", "Hello") -> 4
S = "Hello world"
Delete(S, 6, 6) -> S is "Hello"
Insert(", world", S, 6) -> S is "Hello, world"
Conversions
| Routine | Description |
|---|---|
IntToStr(Value) |
An integer as a string. |
IntToHex(Value, Digits) |
An integer as a hexadecimal string with at least Digits digits: IntToHex(255, 4) is "00FF". |
StrToInt(S) |
A string as an integer; an error if S is not a valid integer. |
StrToIntDef(S, Default) |
A string as an integer, or Default if S is not a valid integer. |
FloatToStr(Value) |
A number as a string. |
FormatFloat(Fmt, Value) |
A number as a string with a Delphi number format: FormatFloat("0.00", 3.14159) is "3.14". |
StrToFloat(S) |
A string as a floating-point number; an error if S is not a valid number. |
VarToStr(V) |
Any value as a string (Null is an empty string). |
Round(X) |
X rounded to the nearest integer; halves are rounded to the even integer: Round(2.5) is 2, Round(3.5) is 4. |
Trunc(X) |
The integer part of X, as an integer: Trunc(-2.7) is -2. |
Int(X) |
The integer part of X, as a floating-point number. |
Frac(X) |
The fractional part of X. |
Number and date conversions use the regional settings of the computer (decimal separator, date format).
Math
| Routine | Description |
|---|---|
Abs(X) |
Absolute value. |
Sqr(X) |
Square (X * X). |
Sqrt(X) |
Square root. |
Exp(X), Ln(X) |
Exponential and natural logarithm. |
Sin(X), Cos(X), ArcTan(X) |
Sine, cosine and arc tangent (angles in radians). |
Odd(X) |
True if the integer X is odd. |
Random |
A random floating-point number from 0 (included) to 1 (excluded). |
Random(Range) |
A random integer from 0 to Range - 1. |
Inc(var X), Dec(var X) |
Increments or decrements the integer variable X by one. |
Date and time
Dates and times are floating-point numbers: the integer part is the number of days since December 30, 1899, and the fractional part is the time of day.
| Routine | Description |
|---|---|
Date, Time, Now |
The current date, time of day, and date and time. |
EncodeDate(Year, Month, Day) |
A date from its parts. |
EncodeTime(Hour, Min, Sec, MSec) |
A time from its parts. |
DecodeDate(Date, var Year, var Month, var Day) |
The parts of a date, in the three variables. |
DecodeTime(Time, var Hour, var Min, var Sec, var MSec) |
The parts of a time, in the four variables. |
DayOfWeek(Date) |
The day of the week, from 1 (Sunday) to 7 (Saturday). |
IncMonth(Date, Months) |
The date plus a number of months (negative to subtract). |
IsLeapYear(Year) |
True if the year is a leap year. |
DateToStr(Date), TimeToStr(Time), DateTimeToStr(DateTime) |
A date, time, or date and time as a string, in the format of the regional settings. |
StrToDate(S), StrToTime(S), StrToDateTime(S) |
A string as a date, time, or date and time. |
FormatDateTime(Fmt, DateTime) |
A date and time as a string with a Delphi date format: FormatDateTime("yyyy-mm-dd hh:nn", Now). |
Add and subtract days directly: Date + 7 is the date one week from today.
Arrays and values
| Routine | Description |
|---|---|
Length(A) |
Number of items of an array. |
Low(A), High(A) |
First and last index of an array. |
VarArrayCreate(Bounds, Type) |
Creates an array: VarArrayCreate([0, 9], 12) has 10 items (indexes 0 to 9) of any type. |
VarArrayLowBound(A, Dim), VarArrayHighBound(A, Dim) |
First and last index of the dimension Dim (1 for the first) of an array. |
VarIsNull(V) |
True if V is the null value. |
Assigned(Obj) |
True if Obj refers to an object. |
SetOf(Values) |
A set made of an array of enumeration values, for routines that expect a set: SetOf([fsBold, fsItalic]). |
Dialogs
| Routine | Description |
|---|---|
ShowMessage(Msg) |
Shows a message. |
InputQuery(Caption, Prompt, var Value) |
Asks the user for a text. Value is the initial text, and receives the typed text. Returns true if the user confirmed, false if the user cancelled. |
Beep |
Plays the default system sound. |
JavaScript example:
var name = "Anna";
if (InputQuery("Welcome", "Your name:", name))
ShowMessage("Hello, " + name);
The application can show these dialogs in its own way, or not allow them (for example in a server application). In a console application, they write to and read from the console.
Errors
| Routine | Description |
|---|---|
Raise(Msg) |
Raises an error with the message Msg. |
LastExceptionMessage |
The message of the error being handled. |
LastExceptionClassName |
The class name of the error being handled. |
LastExceptionLine, LastExceptionCol |
The script position of the error being handled. |
LastExceptionHelpContext |
The help context number of the error being handled. |
See the error handling section of the reference of each language.
Text files
| Routine | Description |
|---|---|
AssignFile(var F, FileName) |
Prepares the variable F to access the file. Call it first. |
Reset(F) |
Opens the file for reading. |
Rewrite(F) |
Creates the file (or empties an existing file) for writing. |
Append(F) |
Opens the file for writing at its end. |
ReadLn(F) |
Reads the next line of the file and returns it. |
EOF(F) |
True when the end of the file was reached. |
Write(F, Value), WriteLn(F, Value) |
Writes a value to the file; WriteLn also writes a line break. |
FilePos(F), FileSize(F) |
The current position and the size of the file. |
CloseFile(F) |
Closes the file. |
ChDir(Dir) |
Changes the current folder. |
Pascal example:
var
F, Line;
begin
AssignFile(F, 'C:\Data\input.txt');
Reset(F);
try
while not EOF(F) do
begin
Line := ReadLn(F);
ShowMessage(Line);
end;
finally
CloseFile(F);
end;
end;
The application may provide richer libraries for files, like TStringList.LoadFromFile.
COM automation (Windows)
| Routine | Description |
|---|---|
CreateOleObject(ClassName) |
Creates a COM automation object: CreateOleObject("Excel.Application"). |
GetActiveOleObject(ClassName) |
The running instance of a COM automation object. |
The properties and methods of the COM object are called with the dot notation, like any other object.
Scripter routines
| Routine | Description |
|---|---|
Interpret(Code) |
Compiles and runs the code in the string Code, in the default language of the application (usually Pascal). |
Scripter, Machine |
The scripter component and the virtual machine that run the script, for advanced use. |
The VBScript library
Applications can also provide the VBScript library, with functions of the VBScript language.
When it is available, scripts load it with uses VBScript (Pascal and Basic) or
import VBScript; (JavaScript), unless the application loads it for all scripts.
| Group | Functions |
|---|---|
| Strings | Asc, InStr, LCase, UCase, Left, Right, Mid, Len, LTrim, RTrim, Replace, Space, String, StrComp, StrReverse, Split, Join |
| Conversions | CBool, CByte, CCur, CDate, CDbl, CInt, CLng, CSng, CStr, Hex, FormatNumber, FormatCurrency, FormatDateTime |
| Tests | IsArray, IsDate, IsEmpty, IsNull, IsNumeric |
| Math | Atn, Fix, Int, Log, Rnd, Randomize, Sgn |
| Date and time | DateSerial, DateValue, DatePart, Day, Month, MonthName, Year, Weekday, WeekdayName, Hour, Minute, Second, TimeSerial, TimeValue, Timer |
| Arrays | LBound, UBound, Redim, RedimPreserve |
| Dialogs | MsgBox, InputBox |
| Objects | CreateObject |
The library also defines the VBScript constants used by these functions: the buttons and icons
of MsgBox (vbOKOnly, vbYesNo, vbQuestion and others), its results (vbOK, vbYes,
vbNo and others), the date formats of FormatDateTime (vbShortDate, vbLongDate and
others) and the comparison modes (vbBinaryCompare, vbTextCompare).