DelphiScript Statements & Operators Supported in Altium Designer

Примечание

Набор доступных функций зависит от вашего уровня доступа к продуктам Altium. Ознакомьтесь с функциями, включенными в различные уровни Подписки на ПО Altium, и функциональными возможностями приложений, предоставляемых платформой Altium 365.

Если вы не видите в своем ПО функцию, описанную здесь, свяжитесь с отделом продаж Altium, чтобы узнать больше.

DelphiScript Statements Copy Link Copied

A statement in DelphiScript is considered 'simple' when it does not contain any other statements. Examples of simple statements are assignment statements and procedure calls.

Simple statements:

X := Y + 10; // assignment
 
ShowMessage('Hello World!'); // procedure call

A compound statement consists of multiple statements.

Compound statements:

1Begin
2  If A > B Then ShowMessage('A is bigger');
3  Else ShowMessage('B is bigger');
4  A := 0;
5  B := 0;
6End;

In Delphi script, when values are assigned to variables, the colon-equal operator is used: :=

When testing for equality, the equality operator is used: =

Conditional Statements

DelphiScript has control statements that affect the flow of execution within a script. The most common control statement is the If..Then conditional statement.

If Then Statement

The If..Then statement is used for conditional control. The syntax is:

1If Condition Then
2  Begin
3  // code here
4  End
5Else
6  Begin
7  // code here
8  End;

Case Of Statement

To avoid a complex set of If statements, these can often be replaced with Case statements. A case statement in an expression is used to select a value, a list of possible values, or a range of values.

Any types can be used in a Case statement because DelphiScript is an untyped language. Case statements can have an Else statement that is executed if none of the labels correspond to the value of the selector (within the Case Of condition).

Example 1:

01Case Char of
02  '+' : Text := 'Plus sign';
03  '-' : Text := 'Minus sign';
04  '*', '/': Text := 'Multiplication or division';
05  '0'..'9': Text := 'Number';
06  'a'..'z': Text := 'Lowercase character';
07  'A'..'Z': Text := 'Uppercase character';
08else
09  Text := 'Unknown character';
10End;

Example 2:

1Case UserName of
2  'Jack', 'Joe' : IsAdministrator := true;
3  'Fred' : IsAdministrator := false;
4else
5  Raise('Unknown User');
6End;

With Statement

The With statement is a DelphiScript shorthand. When referring to a record type variable (or an object), a 'with' statement can be used instead of repeating its name each time.

Normal version:

1Form.Canvas.Pen.Width := 2;
2Form.Canvas.Pen.Color := clSilver;

Version using With:

1With Form.Canvas.Pen do
2Begin
3  Width := 2;
4  Color := clSilver;
5End;

For To Do Loop

The For..To..Do statement provides a method for repeatedly looping through a block of code (one or more lines of code). The basic syntax is:

1For counter := start To end Do
2Begin
3  // code here
4End;

For loops are often used to initialize an array. The counter direction in a For..To..Do loop can be controlled by alternatively using the DownTo keyword to decrement the loop. DelphiScript provides the Break/Exit statement to exit a For..To..Do loop prematurely.

Repeat Until Loop

The Repeat statement is executed repeatedly until the Boolean expression is true. The Repeat statement is always executed at least once.

Example:

1Repeat
2  Write('Enter a value (0..9): ');
3  ShowMessage(IntToStr(I));
4Until (I >= 0) and (I <= 9);

While Do Loop

A While statement is similar to a Repeat statement except that the control condition is evaluated before the first execution of the statement sequence. Hence, if the condition is false, the statement sequence is never executed.

Example:

1Randomize;
2I := 0;
3While I < 1000 do
4Begin
5  I := I + Random (100);
6  Add ('Random Number: ' + IntToStr (I));
7End;

Continue Statement

The Continue statement jumps over the body of a loop, similar to the Goto statement. The continue statement causes the executing script to pass to the next iteration in the current For, While or Repeat loop.

Example:

01var
02  F: File;
03  i: Integer;
04Begin
05  For i := 0 to (FileListBox1.Items.Count - 1) do
06  Begin
07    Try
08    If FileListBox1.Selected[i] Then
09    Begin
10      If not FileExists(FileListBox1.Items.Strings[i]) then
11      Begin
12        MessageDlg('File: ' + FileListBox1.Items.Strings[i] + 'not found', mtError, [mbOk], 0);
13        Continue;
14      End;
15      AssignFile(F, FileListBox1.Items.Strings[i]);
16      Reset(F, 1);
17      ListBox1.Items.Add(IntToStr(FileSize(F)));
18      CloseFile(F);
19    End;
20    Finally
21      { do something here }
22    End;
23  End;
24End;

Goto Label Statement

The Goto statement has the form Goto label which transfers the script execution to the statement marked by the specified label. To mark a statement, the label must be declared first and then the target statement preceded with the label and a colon: label: statement

A Label can be any valid identifier. The Label declaration and Goto statement must belong to the same code block within a script. Therefore it's not possible to jump into, or out of, a procedure or function.

Example:

1Label StartHere;
2  // code
3StartHere: Beep;
4Goto StartHere;

Exit Statement

The Exit statement immediately returns from a function or procedure. If you call Exit from within a Try..Finally block, the Finally part gets executed before the subroutine returns. If the Exit procedure is called from within the main body of the script, then execution of the script will terminate.

Example:

1Begin
2  Server := SchServer;
3  If Server = Nil Then
4  Begin
5    ShowError('No SchServer started');
6    Exit;
7End;

Break Statement

The Break statement causes the executing script to exit out of the current For, While or Repeat loop. Script execution continues from the subsequent executable line after the current loop.

Example:

01Var
02  S: string;
03Begin
04  While True do
05  Begin
06    ReadLn(S);
07    Try
08      if S = '' then Break;
09      WriteLn(S);
10    Finally
11      { do something for all cases }
12    End;
13  End;
14End;

DelphiScript Expression Operators Copy Link Copied

In general, an expression is a valid combination of constants, variables, literal values, operators, and function results. Expressions are used to determine the value to assign to a variable, to compute the parameter of a function or to test for a condition. Expressions can include function calls.

DelphiScript has a number of logical, arithmetic, Boolean and relational operators. These operators are grouped by the order of precedence (see below), which is different to the precedence orders used by Basic, C, etc. For example, the AND and OR operators have precedence compared to the relational one.

If you write a<b and c<d, DelphiScript will do the AND operation first, resulting in an error. To prevent this problem and define the priority, each < expression needs to be enclosed in parentheses: (a<b) and (c<d);

The supported DelphiScript operators listed below are shown by their order of precedence.

Operators Grouped by Precedence

Note that Unary operators have the highest precedence.

Not

Boolean or bitwise NOT.

Multiplicative and Bitwise Operators

*

Arithmetic multiplication.

/

Floating point division.

div

Integer division.

mod

modulus (remainder of integer division).

and

Boolean or bitwise AND.

shl

Bitwise left shift.

shr

Bitwise right shift.

Additive Operators

+

Arithmetic addition, string concatenation.

-

Arithmetic subtraction.

or

Boolean or bitwise OR

xor

Boolean or bitwise EXCLUSIVE OR.

Relational and Comparison Operators (lowest precedence)

=

Test whether equal or not.

<>

Test whether not equal or not.

<

Test whether less than or not.

>

Test whether greater than or not.

<=

Test whether less than or equal to or not.

>=

Test whether greater than or equal to or not.

Also note that the ^ and @ operators are not supported by DelphiScript.

If you find an issue, select the text/image and pressCtrl + Enterto send us your feedback.
Примечание

Набор доступных функций зависит от вашего уровня доступа к продуктам Altium. Ознакомьтесь с функциями, включенными в различные уровни Подписки на ПО Altium, и функциональными возможностями приложений, предоставляемых платформой Altium 365.

Если вы не видите в своем ПО функцию, описанную здесь, свяжитесь с отделом продаж Altium, чтобы узнать больше.