Scripts Reference Summary

This summary consolidates all procedures, functions, types, and key declarations from the scripting reference into quick-reference tables.

Script Procedures

Usine calls these procedures when the script defines them; all are optional.

Procedure When it runs
procedure Init; After each compilation, on the main thread: create the parameters and initialize the state.
procedure Destroy; Before each new compilation and when the module is deleted, once the runs of the script on the other threads have stopped, on the main thread: free what Init allocated.
procedure Process; Every audio block, on the audio thread.
procedure ProcessThread; Every 20 ms on a dedicated real-time thread, for heavy work.
procedure ProcessIDLE; At the UI refresh rate, on the main thread.
procedure Callback(N: Integer); When the parameter N changes; the thread is chosen with TParameter.CallbackMode. Also called with N = CallBackID for the SubscribeChunk notifications, always on the real-time queue thread whatever CallbackMode says: choose CallBackIDs that cannot equal a parameter number (for example $A01).
procedure OnReset; When the module, its patch or its rack is reset, on the main thread. Usine does not reset the parameters of a script: set them back yourself.

Platform

Type Description
plWindowsIntel Windows on x86/x64 processors.
plWindowsARM Windows on ARM processors.
plMacOSIntel macOS on Intel processors.
plMacOSARM macOS on Apple Silicon/ARM processors.
plLinuxIntel Linux on x86/x64 processors.
plLinuxARM Linux on ARM processors.
plIOSARM iOS/iPadOS on ARM processors.
plAndroidARM Android on ARM processors.

Parameter Creation and Layout

Method Description
function CreateParam(caption: string; typ: TParamType, ioTyp : TParamIOType ):TParameter; Creates an inlet/outlet
TParameter.IsInput(val: Boolean) Enables the inlet port.
TParameter.IsOutput(val: Boolean) Enables the outlet port.
TParameter.Scale(val: TScale) Applies linear, logarithmic, or exponential scaling to faders.
TParameter.Color(val: TAlphaColor) Sets the foreground/ON color.
TParameter.OffColor(val: TAlphaColor) Sets the OFF color for switch-style controls.
TParameter.Visible(val: Boolean) Shows or hides the control in the module panel.
TParameter.Min(val: Single) Defines the minimum allowed value.
TParameter.Max(val: Single) Defines the maximum allowed value.
TParameter.MinMaxNoLimit(val: Boolean) Unlocks values beyond the defined min/max.
TParameter.DefaultValue(val: Single) Declares the reset/default value; in Init it also sets the value.
TParameter.Caption(val: String) Updates the displayed caption.
TParameter.Symbol(val: String) Adds a suffix such as ms or %.
TParameter.Format(val: String) Controls numeric formatting via Pascal format strings.
TParameter.StringValue(val: String) Assigns text to string parameters.
TParameter.ListboxString(val: String) Sets combo-box items using comma-text.
TParameter.ReadOnly(val: Boolean) Locks or unlocks user edits.
TParameter.FastCallback(val: Boolean) Toggles fast callbacks for realtime response. DEPRECATED use TParameter.CallbackMode instead
TParameter.CallbackMode(mode: TCallbackMode) Sets the thread on which the parameter's callback executes: cbMainThread, cbImmediate, cbAsync, cbGraphic (cbVideo, cbRealTime and cbNetwork run as cbMainThread)
TParameter.DontSave(val: Boolean) Excludes the parameter from patch persistence.
TParameter.SavedName(val: String) Overrides the storage key used on disk.
TParameter.IsSeparator(val: Boolean) Inserts a blank row before the control in the UI.

CreateParam

Type Description
ptTextField Text field inlet/outlet.
ptColor Color picker inlet/outlet.
ptMIDI MIDI inlet/outlet.
ptGainFader Gain fader inlet/outlet (-84 to +12 dB).
ptAudio Audio inlet/outlet.
ptDataField Numeric inlet/outlet without a fader; click to edit the value.
ptDataFader Numeric inlet/outlet with a mouse-driven fader.
ptButton Momentary trigger inlet/outlet.
ptListBox Combo box inlet/outlet; populate with ListBoxString.
ptSwitch Toggle switch inlet/outlet.
ptArray Array inlet/outlet.
ptIpAddress IPv4-formatted inlet/outlet (xxx.xxx.xxx.xxx).
ptTimecode Timecode inlet/outlet (HH:MM:SS:FF).
ptMIDINoteFader MIDI note fader inlet/outlet for notes 0..127, shown as note names.
ptPointerBitMap Hexadecimal bitmap pointer inlet/outlet.
ptPointer General hexadecimal pointer inlet/outlet.
ptRightLed LED-style toggle inlet/outlet, the LED drawn at the right.
ptLed Former name of ptRightLed, kept for compatibility: the LED drawn at the right.
ptFolderName Folder picker inlet/outlet.
ptChooseFolder Former name of ptFolderName, kept for compatibility.
ptLeftLed LED-style toggle inlet/outlet, the LED drawn at the left.
ptTriggerLed LED trigger inlet/outlet, the LED drawn at the right.
ptFileName File picker inlet/outlet.
ptBitwise Bitwise flag inlet/outlet.
Type Description
pioInput Parameter appears as an inlet.
pioOutput Parameter appears as an outlet.
pioBoth Parameter functions as both inlet and outlet.
pioNone Parameter stays internal and is hidden on the module.

TParameter.Scale

Type Description
lsLinear Linear response; equal steps per unit.
lsLog Logarithmic response; more resolution near the minimum.
lsExp Exponential response; more resolution near the maximum.

TCallbackMode

Mode Description
cbMainThread Default. Callback runs on the main message queue (~25–50 ms). Equivalent to CallbackMode(cbMainThread).
cbImmediate Callback is queued and runs just before the next Process, in the same thread (usually the audio thread). Equivalent to CallbackMode(cbImmediate).
cbAsync Callback runs on the main thread, from a queue processed right after the cbMainThread one (not in the background).
cbVideo Not available to scripts: the callback runs as cbMainThread, and a warning is traced.
cbRealTime Not available to scripts: the callback runs as cbMainThread, and a warning is traced.
cbGraphic Callback runs on the main thread during the graphic/UI refresh pass.
cbNetwork Not available to scripts: the callback runs as cbMainThread, and a warning is traced.

Parameter Value Access

Procedure Description
procedure TParameter.asFloat(val : single); Set the value of a float parameter
function TParameter.asFloat: single; Get the value of a float parameter
procedure TParameter.asInteger(val : integer); Set the value of an integer parameter
function TParameter.asInteger: integer; Get the value of an integer parameter
procedure TParameter.asString(val : string); Set the value of a string parameter
function TParameter.asString: string; Get the value of a string parameter
procedure TParameter.asMidi(index : integer; val : TMIDI); Set the value of a MIDI parameter at the index
function TParameter.asMidi(index : integer): TMIDI; Get the value of a MIDI parameter at the index
procedure TParameter.asArray(index : integer; val : single); Set the value of a float array parameter at the index
function TParameter.asArray(index : integer): single; Get the value of a float array parameter at the index
procedure TParameter.asColor(val : TAlphaColor); Set the value of a color parameter
function TParameter.asColor: TAlphaColor; Get the value of a color parameter
procedure TParameter.asColorArray(index : integer; val : TAlphaColor); Set the value of a color array parameter at the index
function TParameter.asColorArray(index : integer): TAlphaColor; Get the value of a color array parameter at the index
procedure TParameter.asBitWise(val : uInt32); Set the value of a bitwise parameter
function TParameter.asBitWise: uInt32; Get the value of a bitwise parameter
function TParameter.asPointer: single; Returns a pointer to the value
procedure TParameter.Length(l : integer); Set the length of a parameter
function TParameter.Length: integer; Get the length of a parameter
function TParameter.equal1: boolean; Return True if the parameter’s value is equal to 1
function TParameter.equal0: boolean; Return True if the parameter’s value is equal to 0
function TParameter.CopyFromModule(AModuleName, AModuleTletName: string): boolean; Copy the value from a specified module terminal (inlet or outlet) into the current parameter. See dynamic-patching
function TParameter.CopyToModule(AModuleName, AModuleTletName: string): boolean; Copy the current parameter value to a specified module terminal (inlet or outlet); a module setting that is not a control is only written on the main thread. See dynamic-patching
procedure TParameter.ReadFromChunk(ChunkName, ItemName: string); Read a parameter value from a specified chunk and item. See chunks
procedure TParameter.WriteToChunk(ChunkName, ItemName: string); Write a parameter value to a specified chunk and item. See chunks

type TMIDI = record Channel: integer; Msg: integer; Data1: integer; Data2: integer; end; Channel 1 to 16, Msg the status byte without the channel ($90 note on, $80 note off, $B0 control change, ...), Data1 and Data2 0 to 127. See TMIDI.

Dynamic Array

Procedure Description
procedure SetArrayLength(var A: dynamic-array; NewLength: Integer); Set the length of a dynamic array
function GetArrayLength(A: dynamic-array): Integer; Get the length of a dynamic array

Global Array

Procedure Description
function GetGlobalArraySize(name: string): integer; Get the size (number of elements) of a global array
procedure SetGlobalArraySize(name: string; newsize: integer); Set the size (number of elements) of a global array
function GetGlobalArrayFloat(name: string; index: integer): single; Get the float value of a global array element at the given index
procedure SetGlobalArrayFloat(name: string; index: integer; v: single); Set the float value of a global array element at the given index
function GetGlobalArrayColor(name: string; index: integer): TAlphaColor; Get the color of a color global array element at the given index
procedure SetGlobalArrayColor(name: string; index: integer; v: TAlphaColor); Set the color of a color global array element at the given index
function GetGlobalArrayString(name: string; index: integer): string; Get the text of a string global array element at the given index
procedure SetGlobalArrayString(name: string; index: integer; v: string); Set the text of a string global array element at the given index
procedure SetGlobalArrayTrigger(name: string; index: integer); Fire a trigger global array at the given index

The color, string and trigger functions raise a script error on a global array of another type, and no function changes a global constant: see global-array.

Dynamic patching

Procedure Description
function SetTargetPatch(AName: string): boolean; Set the target patch where subsequent module operations will take place. If the AName is empty then the current patch containing the script is used as target. Returns TRUE if a patch named AName is found, FALSE otherwise (also when AName is empty)
function CreateFileModule(Left, Top: integer; AFileName, OptionalContent, AModuleName: string):boolean; Create a new module from a file at the specified position and name, optionally providing inline content. If a module already exists with the specified AModuleName it is deleted before the creation of a new one. Only works on the main thread
function CreateModule(numID, Left, Top, QueryIdx1, QueryIdx2: integer; AModuleName: string):boolean; Create a new module by its numeric ID and position within the patch, see module's id. If a module already exists with the specified AModuleName it is deleted before the creation of a new one; this replacement only works on the main thread
procedure DeleteModule(AName: string); Delete a module of the current target patch by its name, on the main thread only
procedure CreateConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string); Create a connection between two module terminals (source outlet → target inlet)
procedure DeleteConnection(AModuleSrcName, AModuleSrcOutletName, AModuleTargName, AModuleTargInletName: string); Delete an existing connection between two module terminals
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: string); overload; Set a string value on a module terminal (inlet or outlet); a module setting that is not a control is only written on the main thread
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: single); overload; Set a float value on a module terminal; a module setting that is not a control is only written on the main thread
procedure SetModuleValue(AModuleName, AModuleTletName: string; AValue: TAlphaColor); overload; Set a color value on a module terminal; a module setting that is not a control is only written on the main thread
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of single); overload; Set multiple float values on an array-type module terminal; a module setting that is not a control is only written on the main thread
procedure SetModuleArrayValue(AModuleName, AModuleTletName: string; AValues: array of TAlphaColor); overload; Set multiple color values on an array-type module terminal; a module setting that is not a control is only written on the main thread
function GetModuleValue(AModuleName, AModuleTletName: string): TAlphaColor; overload; Get the color value of a module terminal
function GetModuleValue(AModuleName, AModuleTletName: string): single; overload; Get the float value of a module terminal
function GetModuleValue(AModuleName, AModuleTletName: string): string; overload; Get the string value of a module terminal
function GetModulesUserNamesList: string; Return a comma-separated list of the user names, in upper case, of the modules of the current target patch and of its sub-patches
function TParameter.CopyFromModule(AModuleName, AModuleTletName: string): boolean; Copy the value of a module terminal (inlet or outlet) into the parameter
function TParameter.CopyToModule(AModuleName, AModuleTletName: string): boolean; Copy the value of the parameter to a module terminal (inlet or outlet); a module setting that is not a control is only written on the main thread
function LoadPatch(AFileName, ANewPatchName: string): boolean; Loads the current target patch from a file and eventually renames it with a new name. Only works on the main thread, and only when the target patch does not contain the script (not with the default target)
function ClearPatch(AFileName, ANewPatchName: string): boolean; Clears the current target patch and eventually renames it with a new name (AFileName only appears in error messages). Only works on the main thread, and only when the target patch does not contain the script (not with the default target)
function LoadModuleDesign(AModuleName, AFileName: string): boolean; Load a module's visual design from a specified file and apply it to the given module
function SetModuleControlPosition(AModuleName: string; X, Y: single): boolean; Set the on-screen position of a module's control interface
function SetModuleControlSize(AModuleName: string; Width, Height: single): boolean; Set the width and height of a module's control interface

DeleteModule, and CreateModule or CreateFileModule when they replace a module, refuse the script itself and a sub-patch or a procedure that holds it. SetModuleValue and GetModuleValue convert between the type of the call and the type of the port: a whole number (SetModuleValue('OSC1', 'frequency', 440)) selects the TAlphaColor overload and still sets 440 on a number port.

buses

Procedure Description
function GetBusFloat(busname: string): float; Get the current float value of the specified Usine bus
function GetBusArray(busname: string; index: integer): float; Get the float value of a specific element in a Usine bus array
procedure SetBusFloat(busname: string; v: float); Set the float value of the specified Usine bus
procedure SetBusArray(busname: string; index: integer; v: float); Set the float value of a specific element in a Usine bus array

Chunks

Procedure Description
procedure TParameter.ReadFromChunk(ChunkName, ItemName: string); Read a parameter value from a specified chunk and item
procedure TParameter.WriteToChunk(ChunkName, ItemName: string); Write a parameter value to a specified chunk and item
procedure SubscribeChunk(ChunkName, ItemName: string; CallBackID: uint32; Immediate: boolean); Subscribe to changes in a chunk item (the Immediate parameter has no effect)
procedure unSubscribeAll(); Unsubscribe from all previously subscribed chunks
procedure ClearChunkItem(ChunkName, ItemName: string); Empty the content of a chunk item (length 0); the item entry itself remains and ChunkItemExist still returns True — use DeleteChunkItem to remove the entry
procedure DeleteChunkItem(ChunkName, ItemName: string); Remove an item from a chunk; ChunkItemExist then returns False
procedure ClearChunk(ChunkName: string); Clear all data within a specified chunk
function ChunkExist(ChunkName: string): boolean; Return True if the specified chunk exists
function ChunkItemExist(ChunkName, ItemName: string): boolean; Return True if the specified item exists within the chunk

Messaging and Diagnostics

Procedure Description
procedure Trace(S: string; Value: variant); Output a debug message combining a label and a value (variant type) to the Usine trace panel
procedure Trace(S: string); Output a text message to the Usine trace panel
procedure Trace(I: Integer); Output an integer value to the Usine trace panel
procedure Trace(F: Extended); Output a floating-point value to the Usine trace panel
procedure Trace(V: Variant); Output a variant value to the Usine trace panel
procedure Writeln(S: string); Output a text message to the Usine trace panel (same as Trace(S))
procedure Writeln(S1, S2: string); Output S1 followed by S2 on one line of the Usine trace panel
procedure Write(S: string); Same as Writeln(S): every call writes a line of its own
procedure ModuleColor(val: uint32); Set the color of the module ($AARRGGBB, the alpha byte is ignored); SetModuleColor is the same procedure

Transport Commands

Procedure Description
function GetTimecodePos: double; Gets the current Usine timecode position (in seconds or beats, depending on context)
procedure SetTimecodePos(pos: double); Sets the current Usine timecode position to the specified value

IML Messaging

Procedure Description
procedure SendUsineMsgFile(const FileName: string); Send a list of Usine messages stored in a text file
procedure SendUsineMsg(msg: string); Send a single Usine message without arguments
procedure SendUsineMsg(msg, arg1: string); Send a Usine message with one argument
procedure SendUsineMsg(msg, arg1, arg2: string); Send a Usine message with two arguments
procedure SendUsineMsg(msg, arg1, arg2, arg3: string); Send a Usine message with three arguments
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4: string); Send a Usine message with four arguments
procedure SendUsineMsg(msg, arg1, arg2, arg3, arg4, arg5: string); Send a Usine message with five arguments
function GetUsineVariableString(name: string): string; Retrieve the value of a Usine variable as a string; if the variable is not defined, the name itself is echoed back
function GetUsineVariableInteger(name: string): integer; Retrieve the value of a Usine variable as an integer
function GetUsineVariableFloat(name: string): single; Retrieve the value of a Usine variable as a floating-point number

SendUsineMsg and SendUsineMsgFile run only on the main thread (Init, ProcessIDLE, OnReset, Destroy, callbacks in cbMainThread, cbAsync or cbGraphic mode): elsewhere they send nothing and trace a script error. Write the command names in upper case; an unknown command does nothing and reports no error; a message that would free the script is refused. See IML Messages.

Language built-ins

Procedure Description
procedure Swap(var A, B); Exchange the contents of two variables of the same type
function Default(T): T; Return the zero/default value of a type
procedure New(var P: pointer-to-record); Allocate a record for a typed pointer
procedure Dispose(var P: pointer-to-record); Free a record allocated with New

Compound assignments (+=, -=, *=, /=), operator overloading on records and Pascal label/goto are also available — see the overview page.

Error handling

Procedure Description
procedure RaiseException(Ex: string); Raise an error with a message; catch it with try..except
procedure RaiseException(Ex: TIFException; Param: string); Raise an error with a standard code and a message
function ExceptionToString(Ex: TIFException; Param: string): string; Build the message string for an error code
type TIFException Standard error codes: erNoError, erOutOfRange, erDivideByZero, erCustomError, ...

TStringList

Procedure Description
function TStringList.Create: TStringList; Create a new instance of a string list
function TStringList.GetCommaText: String; Return all strings as a single comma-separated string
procedure TStringList.SetCommaText(Comma: string); Set the list contents from a comma-separated string
function TStringList.GetText: String; Return all strings concatenated with line breaks
procedure TStringList.SetText(Text: string); Replace the list contents with text split by line breaks
procedure TStringList.Sort; Sort the list in ascending order
procedure TStringList.SortDesc; Sort the list in descending order
procedure TStringList.SaveToFile(FileName: string); Save the list contents to a file. If no path is given, defaults to the last used location in Usine
procedure TStringList.AppendToFile(FileName: string); Append the list contents to the end of an existing file
procedure TStringList.LoadFromFile(FileName: string); Load list contents from a file. If no path is given, defaults to the last used location in Usine
procedure TStringList.Clear; Clear all strings from the list
procedure TStringList.Free; Free the memory allocated for the list
function TStringList.GetStrings(Index: integer): String; Get the string at the specified index
procedure TStringList.SetStrings(Index: integer; Value: String); Set the string value at the specified index
procedure TStringList.Add(Value: String); Add a new string to the end of the list
procedure TStringList.Delete(Index: integer); Delete the string at the specified index
procedure TStringList.Delete(Value: string); Delete the first string equal to Value, if present
function TStringList.IndexOf(Value: string): integer; Return the index of the specified string, or -1 if not found
function TStringList.Count: integer; Return the number of strings in the list
function TStringList.GetCount: integer; Same as Count; return the total number of strings in the list

TJson

Procedure Description
function TJson.Create: TJson; Create an empty JSON document (root is an empty object)
procedure TJson.Free; Release the document and all its children
procedure TJson.Clear; Reset the document to an empty object
function TJson.Parse(s: string): Boolean; Parse s into the document; returns True on success
function TJson.AsText: string; Serialise the current document back to a compact JSON string
procedure TJson.SaveToFile(FileName: string); Save the document to disk as UTF-8 JSON
function TJson.LoadFromFile(FileName: string): Boolean; Load a JSON file into the document; returns True on success
function TJson.Has(path: string): Boolean; True if a value exists at path
function TJson.Count(path: string): integer; Number of items in an array or members in an object at path
function TJson.Count: integer; Same, for the root document
function TJson.IsArray(path: string): Boolean; True if the node at path is an array
function TJson.IsObject(path: string): Boolean; True if the node at path is an object
function TJson.GetString(path: string): string; Read a string value at path (default: '')
function TJson.GetFloat(path: string): single; Read a numeric value as a float (default: 0)
function TJson.GetInt(path: string): integer; Read a numeric value as an integer (default: 0)
function TJson.GetBool(path: string): Boolean; Read a boolean value at path (default: False)
procedure TJson.SetString(path: string; val: string); Set a string at path, creating missing parents
procedure TJson.SetFloat(path: string; val: single); Set a numeric (float) value at path
procedure TJson.SetInt(path: string; val: integer); Set a numeric (integer) value at path
procedure TJson.SetBool(path: string; val: Boolean); Set a boolean value at path
procedure TJson.SetNull(path: string); Set a JSON null value at path
procedure TJson.SetObject(path: string); Create an empty object at path
procedure TJson.SetArray(path: string); Create an empty array at path
procedure TJson.Remove(path: string); Delete the field or array element at path
procedure TJson.ArrayAddString(path: string; val: string); Append a string element to the array at path
procedure TJson.ArrayAddFloat(path: string; val: single); Append a float element to the array at path
procedure TJson.ArrayAddInt(path: string; val: integer); Append an integer element to the array at path
procedure TJson.ArrayAddBool(path: string; val: Boolean); Append a boolean element to the array at path
procedure TJson.Keys(path: string; resultList: TStringList); Fill resultList with the keys of the object at path

Math and Randomization

Procedure Description
function minS(const A, B: single): single; Return the smaller of two single-precision floating-point values
function maxS(const A, B: single): single; Return the larger of two single-precision floating-point values
function maxI(const A, B: integer): integer; Return the larger of two integer values
function minI(const A, B: integer): integer; Return the smaller of two integer values
function Pi: Extended; Return the mathematical constant π
function Log(e: Extended): Extended; Return the base-10 logarithm of e (same as Log10)
function Exp(e: Extended): Extended; Return e raised to the power of e
function Arctan(e: Extended): Extended; Return the arctangent of e
function Arcsin(e: Extended): Extended; Return the arcsine of e
function Arccos(e: Extended): Extended; Return the arccosine of e
function Abs(d: Extended): Extended; Return the absolute value of an extended value
function Abs(d: Int64): Int64; Return the absolute value of an integer
function Power(Base, Exponent: Extended): Extended; Return Base raised to the power of Exponent
function Sqr(d: Extended): Extended; Return the square of a number
function Sqrt(d: Extended): Extended; Return the square root of a number
function ArcTan(d: Extended): Extended; Return the arctangent of d
function Ln(d: Extended): Extended; Return the natural logarithm of d
function Log10(x: Extended): Extended; Return the base-10 logarithm of x
function Log2(x: Extended): Extended; Return the base-2 logarithm of x
function LogN(Base, x: Extended): Extended; Return the logarithm of x in base Base
function Sin(d: Extended): Extended; Return the sine of an angle
function Cos(d: Extended): Extended; Return the cosine of an angle
function Tan(d: Extended): Extended; Return the tangent of an angle
function ArcTan2(y, x: Extended): Extended; Quadrant-aware arctangent of y / x, in radians from -Pi to Pi: the first argument is y (the C-style name Atan2 does not exist)
function Hypot(x, y: Extended): Extended; Return Sqrt(x*x + y*y)
function Sign(AValue: Extended): Int8; Return -1, 0 or 1 depending on the sign of a float value
function Sign(AValue: Int64): Int8; Return -1, 0 or 1 depending on the sign of an integer value
function Cotan(d: Extended): Extended; Return the cotangent of an angle
function Secant(d: Extended): Extended; Return the secant of an angle
function Cosecant(d: Extended): Extended; Return the cosecant of an angle
function SinH(d: Extended): Extended; Return the hyperbolic sine
function CosH(d: Extended): Extended; Return the hyperbolic cosine
function TanH(d: Extended): Extended; Return the hyperbolic tangent
function ArcSinH(d: Extended): Extended; Return the inverse hyperbolic sine
function ArcCosH(d: Extended): Extended; Return the inverse hyperbolic cosine
function ArcTanH(d: Extended): Extended; Return the inverse hyperbolic tangent
function Exp(d: Extended): Extended; Return e raised to the power of d
function Round(d: Extended): Int64; Round a floating-point value to the nearest integer
function Round(d: Extended; Precision: Int8): Extended; Round a floating-point value to a specified decimal precision
function Frac(d: Extended): Extended; Return the fractional part of a number
function Int(d: Extended): Extended; Return the integer part of a number
function Trunc(d: Extended): Int64; Truncate the fractional part of a number
function Ceil(d: Extended): Int64; Return the smallest integer greater than or equal to d
function Floor(d: Extended): Int64; Return the largest integer less than or equal to d
function DegToRad(Degrees: Extended): Extended; Convert an angle from degrees to radians
function RadToDeg(Radians: Extended): Extended; Convert an angle from radians to degrees
function Lerp(A, B, T: Extended): Extended; Linear interpolation between A and B by factor T (0 to 1)
function SmoothStep(Edge0, Edge1, x: Extended): Extended; Hermite interpolation: 0 below Edge0, 1 above Edge1, smooth in between
function Random(Min, Max: Int64): Int64; Return a random integer between Min and Max
function Random(l: Int64): Int64; Return a random integer from 0 to l - 1
function Random: Extended; Return a random floating-point number between 0.0 and 1.0
procedure Randomize; Initialize the random number generator with a new seed

Date & Time

Procedure Description
var HoursPerDay Number of hours in a day
var MinsPerHour Number of minutes in an hour
var SecsPerMin Number of seconds in a minute
var MSecsPerSec Number of milliseconds in a second
var MinsPerDay Number of minutes in a day
var SecsPerDay Number of seconds in a day
var MSecsPerDay Number of milliseconds in a day
var DateDelta Offset between Delphi’s TDateTime base date and Unix epoch
type TDateTime: double; Represents both date and time as a floating-point value
type TTime: double; Represents only time as a floating-point value
function EncodeDate(Year, Month, Day: UInt16): TDateTime; Create a TDateTime value from year, month, and day
function EncodeTime(Hour, Min, Sec, MSec: UInt16): TDateTime; Create a TDateTime value from hour, minute, second, and millisecond
procedure DecodeDate(DateTime: TDateTime; var Year, Month, Day: UInt16); Extract year, month, and day from a TDateTime value
function DecodeDateFully(DateTime: TDateTime; var Year, Month, Day, DOW: UInt16): Boolean; Decode a TDateTime and return the day of week as well
procedure DecodeTime(DateTime: TDateTime; var Hour, Min, Sec, MSec: UInt16); Extract time components from a TDateTime value
function Date: TDateTime; Return the current system date
function Time: TDateTime; Return the current system time
function Now: TDateTime; Return the current system date and time
function GetTickCount: UInt64; Return the number of milliseconds since system start
procedure Sleep(MilliSeconds: UInt32); Pause execution for a specified number of milliseconds
procedure ReplaceTime(var DateTime: TDateTime; NewTime: TDateTime); Replace the time portion of a TDateTime value
procedure ReplaceDate(var DateTime: TDateTime; NewDate: TDateTime); Replace the date portion of a TDateTime value
function DateTimeInRange(ADateTime: TDateTime; AStartDateTime, AEndDateTime: TDateTime): Boolean; Check if a TDateTime lies within a given range
function FormatDateTime(Format: string; DateTime: TDateTime): string; Return a formatted string representation of a date/time value
function StrToDate(s: string): TDateTime; Convert a string to a date
function StrToDateDef(s: string; Default: TDateTime): TDateTime; Convert a string to a date, returning a default on error
function StrToTime(s: string): TDateTime; Convert a string to a time
function StrToTimeDef(s: string; Default: TDateTime): TDateTime; Convert a string to a time, returning a default on error
function StrToDateTime(s: string): TDateTime; Convert a string to a combined date/time
function StrToDateTimeDef(s: string; Default: TDateTime): TDateTime; Convert a string to a combined date/time, returning a default on error

Files

Procedure Description
function GetApplicationPath: string; Return the absolute path of the current Usine application folder
procedure FindFiles(const Directory: String; Extensions: String; Recursive: Boolean; Result: TStringList); Find all files in a directory matching specific extensions (e.g. 'pat,wkp'), optionally searching recursively
procedure FindDirectories(const Directory: String; Recursive: Boolean; Result: TStringList); Find all subdirectories within a directory, optionally recursively
function WriteFileContents(const FileName: String; const Text: String; Append: Boolean): Boolean; Write text to a file in UTF-8 without BOM, optionally appending to existing content; an empty text writes nothing and returns False
function ReadFileContents(const FileName: String): String; Read the contents of a text file and return as string (empty when the file does not exist). The file is read as UTF-8 (a byte that is not UTF-8 gives the character of the same code, so an ANSI file is read too), or as UTF-16 when it starts with a UTF-16 BOM; a read-only file, or a file another program has open, is read too
function CreateDirectory(const Directory: String): Boolean; Create a single-level directory
function ForceDirectories(const Directory: String): Boolean; Create a full directory path, including intermediate directories
function DeleteDirectory(const Directory: String; OnlyChildren: Boolean): Boolean; Delete a directory or only its contents
function DeleteFile(const FileName: String): Boolean; Delete a specified file
function RenameFile(const OldFileName, NewFileName: String): Boolean; Rename or move a file
function CopyFile(const SourceFileName, DestFileName: String; Overwrite: Boolean = False): Boolean; Copy a file, optionally overwriting an existing one; the source may be read-only
function FileExists(const FileName: String): Boolean; Check whether a file exists
function DirectoryExists(const Directory: String): Boolean; Check whether a directory exists
function FileAge(const FileName: String): Int32; overload; Get the modification date/time of a file as an integer timestamp
function FileAge(const FileName: String; out FileDateTime: TDateTime): Boolean; overload; Get the modification date/time of a file as a TDateTime value
function ExtractFilePath(const FileName: String): String; Extract the directory path from a full file name
function ExtractFileDrive(const FileName: String): String; Extract the drive or volume from a file path
function ExtractFileName(const FileName: String): String; Extract the file name (without path) from a full path
function ExtractFileExt(const FileName: String): String; Extract the file extension from a file name
function ExtractFileDir(const FileName: String): String; Extract the directory portion of a full path
function ExpandFileName(const FileName: String): String; Convert a relative path into an absolute path
function ExtractRelativePath(const BaseName, DestName: String): String; Compute the relative path from one directory to another
function IncludeTrailingPathDelimiter(const Path: String): String; Ensure a path ends with the correct path delimiter
function ExcludeTrailingPathDelimiter(const Path: String): String; Remove the trailing path delimiter from a path
function IncludeTrailingBackslash(const Path: String): String; Ensure a path ends with a backslash (\)
function ExcludeTrailingBackslash(const Path: String): String; Remove a trailing backslash from a path
function IncludeLeadingPathDelimiter(const Path: String): String; Ensure a path starts with a path delimiter
function ExcludeLeadingPathDelimiter(const Path: String): String; Remove a leading path delimiter from a path
function SubFileExt(FileName: String): string; Return the file name without its extension
function PathDelim: string; Return the platform-specific path delimiter ('/' on macOS and Linux, '\' on Windows)
procedure CreateDir(Dir: String); Create a directory (legacy compatibility version)

Strings

EvalBool is the boolean type returned by the built-in functions of the script engine (a 32-bit LongBool): use it like a Boolean. Script strings are 1-based, unlike the string modules.

Procedure Description
type TTextLineBreakStyle = (tlbsLF, tlbsCRLF, tlbsCR); Defines possible line break styles (Line Feed, Carriage Return + Line Feed, Carriage Return)
type TReplaceFlags = set of (rfReplaceAll, rfIgnoreCase); Flags used for string replacement options
function UpperCase(s: string): string; Convert all characters in a string to uppercase
function LowerCase(s: string): string; Convert all characters in a string to lowercase
function UpCase(c: AnsiChar): AnsiChar; Convert a single ANSI character to uppercase
function UpCase(c: WideChar): WideChar; Convert a single wide character to uppercase
function CompareStr(s1, s2: string): Int32; Compare two strings case-sensitively
function CompareMem(p1, p2: Pointer; Length: PtrUInt): EvalBool; Compare two memory blocks for equality
function CompareText(s1, s2: string): Int32; Compare two strings ignoring case
function SameText(s1, s2: string): EvalBool; Return True if two strings are equal ignoring case
function Copy(s: string; ifrom, icount: Longint): string; Copy a substring from a string
procedure Delete(var s: string; ifrom, icount: Longint); Delete a substring from a string
procedure Insert(s: string; var s2: string; ipos: Longint); Insert a substring into another string at a given position
s[i] : Char Read or write the character at index i (1-based) with direct indexing: c := s[2]; / s[2] := 'X';
function StrGet(var S: String; i: Integer): Char; Get the character at index i in a string
function StrGet2(S: String; i: Integer): Char; Get the character at index i (by-value variant)
procedure StrSet(c: Char; I: Integer; var s: String); Set the character at position I in a string
function WStrGet(var S: WideString; i: Integer): WideChar; Get the character at index i in a WideString
function Length(s: String): Longint; Return the number of characters in a string
procedure SetLength(var S: String; L: Longint); Set the length of a string
function AnsiUpperCase(s: string): string; Convert a string to uppercase using locale-specific rules
function AnsiLowerCase(s: string): string; Convert a string to lowercase using locale-specific rules
function AnsiCompareStr(s1, s2: string): Int32; Compare two strings case-sensitively using ANSI rules
function AnsiCompareText(s1, s2: string): Int32; Compare two strings case-insensitively using ANSI rules
function AnsiSameText(s1, s2: String): EvalBool; Return True if two strings are equal ignoring case (ANSI version)
function AnsiSameStr(s1, s2: String): EvalBool; Return True if two strings are exactly equal (ANSI version)
function Trim(s: string): string; Remove leading and trailing spaces from a string
function TrimLeft(s: string): string; Remove leading spaces from a string
function TrimRight(s: string): string; Remove trailing spaces from a string
function PadL(s: string; Len: SizeInt; c: Char = ' '): string; Pad a string on the left to a given length using the specified character
function PadR(s: string; Len: SizeInt; c: Char = ' '): string; Pad a string on the right to a given length using the specified character
function Padz(s: string; Len: SizeInt): string; Pad a string on the left with zeros (same as PadL(s, Len, '0'))
function QuotedStr(s: string): string; Return a quoted version of a string
function AnsiQuotedStr(s: string; Quote: Char): string; Return a string enclosed by a specific quote character
function AnsiDequotedStr(s: string; AQuote: Char): string; Remove quotes from a quoted string
function WrapText(Line, BreakStr: string; BreakChars: set of AnsiChar; MaxCol: Int32): string; Wrap a text line into multiple lines based on maximum column width
function AdjustLineBreaks(s: string; Style: TTextLineBreakStyle): string; Convert line breaks to a given line break style
function IntToHex(Value: Int64; Digits: Int32 = 1): string; Convert an integer value to a hexadecimal string
function IntToHex(Value: UInt64; Digits: Int32 = 1): string; Convert an unsigned integer value to a hexadecimal string
function IntToStr(i: Int64): string; Convert an integer to its string representation
function IntToStr(i: UInt64): string; Convert an unsigned integer to its string representation
function Int64ToStr(i: Int64): string; Convert a 64-bit integer to a string (same as IntToStr)
function UInt64ToStr(i: UInt64): string; Convert an unsigned 64-bit integer to a string (same as IntToStr)
function StrToInt(s: string): Int32; Convert a string to an integer
function StrToIntDef(s: string; Def: Int32): Int32; Convert a string to an integer, returning a default value on error
function StrToInt64(s: string): Int64; Convert a string to a 64-bit integer
function StrToInt64Def(s: string; Def: Int64): Int64; Convert a string to a 64-bit integer, returning a default on error
function StrToUInt64(s: string): UInt64; Convert a string to an unsigned 64-bit integer
function StrToUInt64Def(s: string; Def: UInt64): UInt64; Convert a string to an unsigned 64-bit integer, returning a default on error
function FloatToStr(f: Extended): string; Convert a floating-point value to a string
function StrToFloat(s: string): Extended; Convert a string to a floating-point value
function StrToFloatDef(s: string; Def: Extended): Extended; Convert a string to a float, returning a default value on error
function CurrToStr(Value: Currency): string; Convert a currency value to a string
function StrToCurr(s: string): Currency; Convert a string to a currency value
function StrToCurrDef(s: string; Def: Currency): Currency; Convert a string to a currency value, returning a default on error
function StrToBool(s: string): EvalBool; Convert a string to a boolean value
function BoolToStr(B: EvalBool; TrueS: string = 'True'; FalseS: string = 'False'): string; Convert a boolean value to its string representation
function StrToBoolDef(s: string; Default: EvalBool): EvalBool; Convert a string to a boolean value, returning a default on error
function Format(Fmt: string; Args: array of Variant): string; Format a string using placeholders and argument values
function FormatFloat(Format: string; Value: Extended): string; Format a floating-point value according to a format string
function FormatCurr(Format: string; Value: Currency): string; Format a currency value according to a format string
function LastDelimiter(Delimiters, s: string): SizeInt; Return the position of the last delimiter character in a string
function StringReplace(S, OldPattern, NewPattern: string; Flags: TReplaceFlags): string; Replace occurrences of a substring within a string using flags for case and repetition
function IsDelimiter(Delimiters, s: string; Index: SizeInt): EvalBool; Check if a character at a given position is one of the specified delimiters
function Pos(Substr: string; Source: string): SizeInt; Return the position of a substring within another string
function StringOfChar(c: Char; l: SizeInt): string; Create a string made of the same character repeated l times
function Replicate(c: Char; l: SizeInt): string; Build a string of l repetitions of a character (same as StringOfChar)

String helpers

Procedure Description
function string.StartsWith(AValue: string): boolean; Return True if the string begins with the specified substring AValue
function string.EndsWith(AValue: string): boolean; Return True if the string ends with the specified substring AValue

Color helpers

Procedure Description
function TAlphaColor.A: integer; overload; Get the alpha (transparency) component of the color
procedure TAlphaColor.A(V: integer); overload; Set the alpha (transparency) component of the color
function TAlphaColor.R: integer; overload; Get the red component of the color
procedure TAlphaColor.R(V: integer); overload; Set the red component of the color
function TAlphaColor.G: integer; overload; Get the green component of the color
procedure TAlphaColor.G(V: integer); overload; Set the green component of the color
function TAlphaColor.B: integer; overload; Get the blue component of the color
procedure TAlphaColor.B(V: integer); overload; Set the blue component of the color

windows registry

Procedure Description
procedure WriteRegistryInteger(AKey, AName: string; AValue: integer); Write an integer value to the Windows registry under the specified key and name
procedure WriteRegistryString(AKey, AName: string; AValue: string); Write a string value to the Windows registry under the specified key and name
function ReadRegistryInteger(AKey, AName: string): integer; Read an integer value from the Windows registry for the specified key and name
function ReadRegistryString(AKey, AName: string): string; Read a string value from the Windows registry for the specified key and name

variants

Type Description
varEmpty The variant is unassigned
varNull The variant is Null
varAny A variant that can hold any value
varSmallint 16-bit signed integer (Smallint in Delphi, short in C++)
varInteger 32-bit signed integer (Integer in Delphi, int in C++)
varSingle Single-precision floating-point value (Single in Delphi, float in C++)
varDouble Double-precision floating-point value (Double)
varCurrency Currency floating-point value (Currency)
varDate Date and time value (TDateTime)
varOleStr Reference to a dynamically allocated UNICODE string
varDispatch Reference to an Automation object (IDispatch pointer)
varError Operating system error code
varBoolean 16-bit Boolean (WordBool)
varVariant Indicates another variant
varUnknown Reference to an unknown object (IUnknown or IInterface pointer)
varShortInt 8-bit signed integer (ShortInt or signed char)
varByte 8-bit unsigned byte
varWord Unsigned 16-bit value (Word)
varLongWord Unsigned 32-bit value (LongWord or unsigned long)
varInt64 64-bit signed integer (Int64 or __int64)
varStrArg COM-compatible string
varString Reference to a dynamically allocated non-COM string
varArray Indicates a Variant array
varByRef Indicates the variant contains a reference instead of a value
varTypeMask Type mask for array elements
Procedures
Procedure Description
function VarType(const V: Variant): TVarType; Return the type code of a variant
function VarAsType(const V: Variant; aVarType: TVarType): Variant; Convert a variant to a specific variant type
function VarIsByRef(const V: Variant): EvalBool; Return True if the variant contains a reference
function VarIsEmpty(const V: Variant): EvalBool; Return True if the variant is unassigned
function VarIsNull(const V: Variant): EvalBool; Return True if the variant is Null
function VarIsClear(const V: Variant): EvalBool; Return True if the variant is cleared or uninitialized
function VarIsError(const V: Variant; out AResult: HRESULT): EvalBool; Return True if the variant contains an error value
function VarAsError(AResult: HRESULT): Variant; Create a variant representing a COM error code
function VarIsCustom(const V: Variant): EvalBool; Return True if the variant is of a custom (user-defined) type
function VarIsOrdinal(const V: Variant): EvalBool; Return True if the variant contains an ordinal (integer-like) type
function VarIsFloat(const V: Variant): EvalBool; Return True if the variant contains a floating-point number
function VarIsNumeric(const V: Variant): EvalBool; Return True if the variant contains a numeric type
function VarIsStr(const V: Variant): EvalBool; Return True if the variant contains a string
function VarIsArray(const A: Variant; AResolveByRef: EvalBool = True): EvalBool; Return True if the variant is an array
function VarToStr(const V: Variant): string; Convert a variant to a string
function VarToStrDef(const V: Variant; ADefault: string): string; Convert a variant to a string; the default is returned for a Null variant (an unassigned variant converts to an empty string)
function VarToWideStr(const V: Variant): WideString; Convert a variant to a WideString
function VarToWideStrDef(const V: Variant; ADefault: WideString): WideString; Convert a variant to a WideString with default value
function VarToUnicodeStr(const V: Variant): UnicodeString; Convert a variant to a UnicodeString
function VarToUnicodeStrDef(const V: Variant; ADefault: UnicodeString): UnicodeString; Convert a variant to a UnicodeString with default value
function VarToDateTime(const V: Variant): TDateTime; Convert a variant to a TDateTime
function VarFromDateTime(DateTime: TDateTime): Variant; Convert a TDateTime to a variant
function VarInRange(const AValue, AMin, AMax: Variant): EvalBool; Return True if a variant value is within a range
function VarEnsureRange(const AValue, AMin, AMax: Variant): Variant; Clamp a variant to a specified range
function VarSameValue(const A, B: Variant): EvalBool; Return True if two variants have the same value
function VarCompareValue(const A, B: Variant): TVariantRelationship; Compare two variants and return their relationship
function VarTypeIsValidArrayType(aVarType: TVarType): EvalBool; Return True if the type can be used as an array type
function VarTypeIsValidElementType(aVarType: TVarType): EvalBool; Return True if the type can be used as an element type in a variant array
function VarArrayCreate(Bounds: array of SizeInt; aVarType: TVarType): Variant; Create a variant array of the given bounds and element type
function VarArrayOf(Values: array of Variant): Variant; Create a variant array initialized with given values
procedure VarArrayRedim(var A: Variant; HighBound: SizeInt); Change the upper bound of the last dimension in a variant array
function VarArrayAsPSafeArray(const A: Variant): Pointer; Return a pointer to the SAFEARRAY representing the variant array
procedure VarCopyNoInd(var Dest: Variant; const Source: Variant); Copy a variant value without dereferencing references
function VarArrayDimCount(const A: Variant): SizeInt; Return the number of dimensions in a variant array
function VarArrayLowBound(const A: Variant; Dim: SizeInt): SizeInt; Return the lower bound of a specified array dimension
function VarArrayHighBound(const A: Variant; Dim: SizeInt): SizeInt; Return the upper bound of a specified array dimension
function VarArrayLock(const A: Variant): Pointer; Lock a variant array and return a pointer to its data
procedure VarArrayUnlock(const A: Variant); Unlock a previously locked variant array
function VarArrayRef(const A: Variant): Variant; Return a reference to a variant array
function VarArrayGet(const A: Variant; Indices: array of Int32): Variant; Retrieve an element from a variant array by index
procedure VarArraySet(var A: Variant; const Value: Variant; Indices: array of Int32); Assign a value to a variant array element by index
Constants
Constant Value Description
S_OK 0 No error, the operation succeeded (often interpreted as True)
S_FALSE $00000001 No error, but the operation did not produce a meaningful result (often interpreted as False)
E_NOINTERFACE $80004002 The requested interface is not supported by the object
E_UNEXPECTED $8000FFFF Catastrophic or unexpected failure
E_NOTIMPL $80004001 Operation not implemented

version 7.0.250921

Edit All Pages