# Standard Routines (Scripting Module)

The Scripting Module provides the following types of Standard Routines: ▪Math/Number ▪String ▪File ▪Date & Time ▪Miscellaneous Math/Number Routines The following functions and procedures are available:
Routine | Description
Abs(X: Number): Number | Returns the absolute value of the argument, X. X is an integer-type or real-type expression.
ArcTan(X: Float): Float | Returns the arctangent of X. X is a real-type expression that gives an angle in radians.
Cos(X: Float): Float | Returns the cosine of the angle X. X is a real-type expression that represents an angle in radians.
Dec(var X: Integer; N: Integer = 1) | Decrements a variable by 1 or N.
Exp(X: Float): Float | Returns the exponential of X. Exp returns the value of e raised to the power of X, where e is the base of the natural logarithms.
FloatToStr(Value: Float): String | Converts a floating point value to a string.
FormatFloat(const Format: String; Value: Float): String | Formats a floating point value.
Frac(X: Float): Float | Returns the fractional part of a real number.
High(X: Type): Integer | Returns the highest value in the range of an argument.
Inc(var X: Integer; N: Integer = 1) | Increments an ordinal value by one or N.
Int(X: Float): Float | Returns the integer part of a real number.
IntToHex(Value, Digits: Integer): String | Returns the hexadecimal representation of an integer.
IntToStr(Value: Integer): String | Converts an integer to a string.
Ln(X: Float): Float | Returns the natural logarithm (Ln(e) = 1) of the real-type expression X.
Log10(X: Float): Float | Calculates log base 10.
Low(X: Type): Integer | Returns the lowest value in a range.
Odd(X: Integer): Boolean | Returns True if X is an odd number.
Ord(X: Char): Byte | Returns the ordinal value of an ordinal-type expression.
Power(Base: Float; const Exponent: Float): Float | Raises Base to any power.
Random(ARange: Integer): Integer | Generates random numbers within a specified range.
Round(X: Float): Integer | Returns the value of X rounded to the nearest whole number.
Sin(X: Float): Float | Returns the sine of the angle in radians.
Sqr(X: Number): Float | Returns the square of a number.
Sqrt(X: Number): Float | Returns the square root of X.
StrToFloat(S: String): Float | Converts a given string to a floating-point value.
StrToInt(S: String): Integer | Converts a string that represents an integer to a number.
StrToIntDef(S: String; Default: Integer): Integer | Converts a string that represents an integer to a number with default value if the string is invalid.
Tan(X: Float): Float | Returns the tangent of X.
Trunc(X: Float): Integer | Truncates a real number to an integer.
String Routines The following functions and procedures are available:
Routine | Description
AnsiCompareStr(S1, S2: String): Integer | Compares S1 to S2, with case sensitivity. Returns a value less than 0 if S1 < S2, a value greater than 0 if S1 > S2, and returns 0 if S1 = S2.
AnsiCompareText(S1, S2: String): Integer | Compares S1 to S2, without case sensitivity. Returns a value less than 0 if S1 < S2, a value greater than 0 if S1 > S2, and returns 0 if S1 = S2.
AnsiLowerCase(S: String): String | Returns a string that is a copy of the given string converted to lowercase.
AnsiUpperCase(S: String): String | Returns a string that is a copy of the given string converted to upper case.
Chr(X: Integer): Char | Returns the character with the ordinal value (ASCII value) of the byte-type expression, X.
CompareStr(S1, S2: String): Integer | Compares S1 to S2, with case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2.
CompareText(S1, S2: String): Integer | Compares S1 to S2, without case-sensitivity. The return value is less than 0 if S1 is less than S2, 0 if S1 equals S2, or greater than 0 if S1 is greater than S2.
Copy(S: String; Index: Integer; Count: Integer): String | Returns a substring of a string.
Delete(var S: String; Index: Integer; Count: Integer) | Removes a substring from a string.
Format |
Insert(Substr: String; var Dest: String; Index: Integer) | Inserts a substring into a string beginning at a specified point.
Length(S: String): Integer | Returns the number of characters in a string.
LowerCase(S: String): String | Converts a string to lowercase.
Pos(substr: String; str: String): Integer | Returns the index value of the first character in a specified substring that occurs in a given string.
Trim(S: String): String | Trims leading and trailing spaces from a string.
TrimLeft(S: String): String | Trims leading spaces from a string.
TrimRight(S: String): String | Trims trailing spaces from a string.
UpperCase(S: String): String | Converts a string to uppercase.
File Routines The following file-handling routines are available:
Routine | Description
Append(FileHandle: Integer) | Prepares an existing file for adding text to the end.
AssignFile(var FileHandle: Integer; FileName: String) | Associates the name of an external file with FileHandle.
Chdir(S: String) | Changes the current directory to the path specified by S. The path can include a drive specifier, which causes the current drive to be changed as well.
CloseFile(var FileHandle: Integer) | Closes the external file associated with FileHandle.
EOF(FileHandle: Integer): Boolean | Tests whether the file position is at the end of a file.
Execute(Filename: String): Integer | Calls Window's ShellExecute with the 'open' parameter for the specified Filename.
FileExists(Filename: String): Boolean | Returns True if the specified Filename exists; False, otherwise.
FilePos(FileHandle: Integer): Integer | Returns the current file position.
FileSize(FileHandle: Integer): Integer | Returns the number of records in a file.
GetTempFilename: String; | Returns a temporary filename.
GetTempFilenameEx(Path: String): String | Returns a temporary filename, in the specified path.
ReadLn(FileHandle: Integer): String | Reads a line of text from a file.
Reset(var FileHandle: Integer) | Opens the existing external file with the name assigned to FileHandle by AssignFile.
Rewrite(var FileHandle: Integer) | Creates a new external file with the name assigned to FileHandle by AssignFile.
Write(FileHandle: Integer; S: String) | Writes a string to a file, but does not add a new line.
WriteLn(FileHandle: Integer; S: String) | Writes a string to a file, adding a new line.
Example: var myFile; begin // Try to open the Test.txt file for writing to AssignFile(myFile, 'c:\Test.txt'); try ReWrite(myFile); // Write a couple of words to this file WriteLn(myFile, 'Hello'); WriteLn(myFile, 'World'); finally // No matter what happens, close the file. CloseFile(myFile); end; end; Date & Time Routines The following functions and procedures are available:
Routine | Description
Date: Integer | Returns the current local date as a TDateTime value. The time portion of the value is 0 (midnight).
DateTimeToStr(Date: TDateTime): String | Converts a TDateTime value to a string.
DateToStr(Date: TDateTime): String | Converts a TDateTime value to a string.
DayOfWeek(Date: TDateTime): Integer | Returns the day of the week for a specified date.
DecodeDate(DateTime: TDateTime; var Year, Month, var Day: Word) | Returns Year, Month, and Day values for a TDateTime value.
DecodeTime(DateTime: TDateTime; var Hour, Min, Sec, MSec: Word) | Breaks a TDateTime value into hours, minutes, seconds, and milliseconds.
EncodeDate(Year: Word; Month: Word; Day: Word): TDateTime; | Returns a TDateTime value that represents a specified Year, Month, and Day.
EncodeTime Hour: Word; Min: Word; Sec: Word; MSec: Word): TDateTime | Returns a TDateTime value for a specified Hour, Min, Sec, and MSec.
FormatDateTime(const Format: String; DateTime: TDateTime): String | Formats a TDateTime value using Format.
IncMonth(DateTime: TDateTime; NumberOfMonths: Integer): TDateTime | Returns a date shifted by a specified number of months.
Now: TDateTime | Returns the current date and time.
StrToDate(S: String): TDateTime | Converts a string to a TDateTime value.
StrToDateTime(S: String): TDateTime | Converts a string to a TDateTime value.
StrToTime (S: String): TDateTime | Converts a string to a TDateTime value.
Time: TDateTime | Returns the current time.
TimeToStr(DateTime: TDateTime): String | Returns a string that represents a TDateTime value.
Example: var Today; begin Today := Date; ShowMessage(DateToStr(Today)); end; Miscellaneous Routines The following functions and procedures are available:
Routine | Description
Assigned(V: Type): Boolean | Returns True if variable V is assigned.
Beep | Beep generates a message beep.
InputQuery(Acaption, APrompt: String; var Value: String): Boolean | Displays an input dialog that lets the user enter a string, double, or integer.
Interpret(Ascript) | Executes the script source code specified by Ascript parameter.
IsValidIdent(S: String): Boolean | Returns true if the given string is a valid identifier. An identifier is defined as a character from the set ['A'..'Z', 'a'..'z', '_'] followed by zero or more characters from the set ['A'..'Z', 'a'..'z', '0..'9', '_'].
Machine | Returns the current virtual machine executing the script.
Raise(Error: Integer) | Create an exception.
Scripter | Scripter returns the current scripter component.
SetOf(Set: Array) | SetOf returns a set from the array passed. For example: MyFontStyle := SetOf([fsBold, fsItalic]);
ShowMessage(Msg: String) | Displays a message box with an OK button.
Sleep(NumSeconds: Integer) | Delay program execution for the specified number of seconds.
VarArrayCreate(Bounds: IntegerArray; AVarType: Integer): Variant | Creates a variant array with the specified Bounds and the element type given by AVarType.
VarArrayHighBound(A: Variant; Dim: Integer = 0): Integer | Returns the high bound for a dimension in a variant array.
VarArrayLowBound(A: Variant; Dim: Integer = 0): Integer | Returns the low bound of a dimension in a variant array.
VarIsNull(V: Variant): Boolean | Indicates whether the specified variant is Null.
VarToStr(V: Variant): String | Converts a variant's value to a string.