Created: January 09, 2020 | Updated: July 23, 2021
| Applies to versions: 3.1, 3.2, 4 and 5
Nexus message
This documentation page references Altium NEXUS/NEXUS Client (part of the deployed NEXUS solution), which has been discontinued. All your PCB design, data management and collaboration needs can now be delivered by Altium Designer and a connected Altium 365 Workspace. Check out the FAQs page for more information.
Differences between DelphiScript and Delphi
Copy LinkCopied
This section covers the essential differences between the DelphiScript scripting language and Embarcadero's Delphi programming language, and how this applies to the Altium NEXUS API.
The Altium NEXUS scripting system uses untyped DelphiScript language so there are no data types in scripts. Although you can declare variables and their types, and specify the types for functions/procedures or method parameters for readability, DelphiScript will convert undeclared variables when a script is being executed. So for example, you cannot define records or classes.
Delphi Script Variables
All variables in a script are of Variant type, and Types in a variable declaration are ignored and can be skipped. So these three declarations are correct:
In general, variants can be used to store any data type and perform numerous operations and type conversions. A variant is type-checked and computed at run time. The compiler won't provide a warning of possible errors in the code, which can be caught only with extensive testing. On the whole, the code portions that use variants can be considered to be interpreted code, because many operations cannot be resolved until run time. This can affect the speed of the code.
The result of this is that once a variant variable has been declared and has obtained a variant value, it can be copied to any compatible or incompatible data type:
// variable V can be assigned values of several different types:
5
V := 10;
6
V := 'Hello, World';
7
V := 45.55;
8
End;
If an incompatible data type has been assigned to a variable the DelphiScript interpreter performs a conversion where possible. Otherwise, a run-time error is issued. In practice, a variant stores type information along with the data so DelphiScript is slower than the equivalent Embarcadero Delphi compiled code.
Sets in Scripts
DelphiScript does not have Set types and does not support Set operators, unlike the Delphi language which does have Set types and supports Set operators.
To use Sets in DelphiScript scripts, use the built-in functions that manipulate sets in a script.
When considering using Functions and Procedures inside a Function or Procedure, the recommended approach is to write standalone functions/procedures — although recursive procedures/functions are permitted.
The following function snippet is not recommended:
New classes cannot be defined in DelphiScript, but you can use existing DelphiScript classes and instantiate them. For example the TList and TStringList classes can be created and used in your scripts. See also TList TStringList
CreateObject Function
The CreateObject function can be used to create objects that will be implicitly freed when no longer used.
The Raise keyword can be used without parameters to re-raise the last exception. Raise can also be used with a string parameter to raise the exception with the specified message string. The Exception objects are not supported in DelphiScript, because the On keyword is not supported.
In Delphiscript, the Threadvar keyword is treated as Var. Note that in Embarcadero Delphi, the variables declared using the Threadvar keyword have distinct values in each thread.
Set Operators
The Set operator In is not supported. The InSet operator can be used to check whether a value is a member of a set. For example:
Note that Delphi set operators +, -, *, <=, >= do not work correctly. The built-in Delphiscript functions MkSet, MkSetRange, SetUnion, SetDifference, SetIntersection, SubSet and InSet are used instead:
See also
MkSet keyword
MkSetRange keyword
InSet keyword
SetDifference keyword
SetIntersection keyword
SetUnion keyword
SubSet keyword
InSet keyword
Operators
The ^ and @ operators are not supported.
Directives
The following directives are not supported (note that some are obsolete, and are also not supported by Embarcadero Delphi): absolute, abstract, assembler, automated, cdecl, contains, default, dispid, dynamic, export, external, far, implements, index, message, name, near, nodefault, overload, override, package, pascal, private protected, public, published, read, readonly, register, reintroduce, requires, resident, safecall, stdcall, stored, virtual, write, writeonly.
Also, note that the in directive in the Uses clause is ignored.
Ignored Keywords
The interface, implementation, program and unit keywords are ignored in DelphiScript. The scripts can contain them but they have no effect — however, these keywords can enhance the readability of scripts.
Unsupported Keywords
The following keywords are not supported in DelphiScript:
The functions from the Delphi's Windows unit (the windows.pas file) are not supported (for example the RGB function is not supported).
Using the Altium NEXUS API in scripts
Copy LinkCopied
You cannot create your own records or classes types using DelphiScript and instantiate them in a script, however, you can use certain classes from the Altium NEXUS API. For example, the TStringList and TList classes can be instantiated and used as containers of data storage (usually of the same type) to meet the needs of a script.
The API's Object Interfaces that represent Altium NEXUS objects are available to use in scripts. For example, you have the ability to update design objects on Schematic and PCB documents through the use of Schematic object interfaces and PCB objects interfaces.
As a convention, interface names have an 'I' added in front of the name. For example IPCB_Board represents an interface for an existing PCB document.
Via := PCBServer.PCBObjectFactory(eViaObject, eNoDimension, eCreate_Default);
11
Via.X := MilsToCoord(7500);
12
Via.Y := MilsToCoord(7500);
13
Via.Size := MilsToCoord(50);
14
Via.HoleSize := MilsToCoord(20);
15
Via.LowLayer := eTopLayer;
16
Via.HighLayer := eBottomLayer;
17
18
(* Put this via in the Board object*)
19
Board.AddPCBObject(Via);
20
End;
The following APIs can be used in Scripts:
Certain Embarcadero Delphi™ functions and classes, and DelphiScript extensions
Client API
PCB Server API
Schematic Server API
Workspace Manager Server API
Integrated Library API
Altium NEXUS API functions
Parametric processes
More Information
Check the scripts in the downloadable scripts collection to see Altium NEXUS Object Interfaces and functions, plus Delphi objects and functions being used in scripts.
Refer to the main Scripting documentation for information on writing scripts for Altium NEXUS.
Refer to the Using the Altium NEXUS API guide for details on how to use design objects and their interfaces in your scripts.
Refer to the Altium NEXUS API Reference for information on the range of Altium NEXUS APIs and their Interface Objects for scripts.
If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.