关键词
本参考资料涵盖用于 Altium Designer 脚本系统的 DelphiScript 关键字。脚本系统支持 DelphiScript 语言,它与 Embarcadero Delphi™ 编程语言非常相似。主要区别在于 DelphiScript 是一种无类型的脚本语言。
本节概述了 DelphiScript 常用关键字的详细信息和示例。有关 Delphi 文件、数学和字符串处理例程等更多关键字信息,请参阅函数和Embarcadero Delphi 参考。
还有
And
如果运算符是布尔类型的,And
Var I, J : Integer Begin I := $F0; J := $8F; ShowMessage(IntToStr(I and J)); End;
Var S : String; Begin S := ''; If (Length(S) > 0) and (S[1\] = 'X') Then Delete(S,1,1); End;
阵列
Array [index range];
DelphiScript 是一种无类型语言,因此需要指定数组的大小或范围。数组可容纳的元素类型仍可定义,但并非必须。不支持Open array
var x : array [1..2];
开始
Begin
statement
End;
begin
Var Test : Integer; Begin Test := Test + 4; ShowMessage(IntToStr(Test)); End;
结束关键字
休息
Break;
BreakGoto
While Condition Do Begin DoSomething; Begin If AnotherCondition Then Break; End; End;
虽然关键词
继续关键字
执行关键字
重复关键字
案例
Case expression Of
Value range : Expression;
Else Expression;
End;
Case
在许多情况下,可以用CaseIfcasecaseCaseelseCase Of
Case Char Of '+' : Text := 'Plus sign'; '-' : Text := 'Minus sign'; '*', '/': Text := 'Multiplication or division'; '0'..'9': Text := 'Number'; 'a'..'z': Text := 'Lowercase character'; 'A'..'Z': Text := 'Uppercase character'; Else Text := 'Unknown character'; End;
Case UserName Of Jack', 'Joe' : IsAdministrator := true; 'Fred' : IsAdministrator := false; Else Raise('Unknown User'); End;
关键词
继续
Continue
ContinueGoto
Var I := 0; s:= 1; Begin While True Do Begin S := S \* 2; I := I \\+ 1; If I > 4 then continue; Break; End;
断开关键字
同时关键字
继续关键字
Do 关键字
重复关键字
Const
Const
Name = Expression;
Constconst
Const b = 30; Begin ShowMessage(IntTtStr(b)); End;
例如,如果试图更改b const
Const b = 30; Begin b := 40; ShowMessage(IntToStr(b)); End;
分部
dividend div divisor
Div
做
-
声明For variable := expression1 to expression2 do -
声明While expression do -
声明。With expression do
DoFor, While and With
For i := 0 To AnIndex - 1 Do S := S + #13 + AString;
用于关键词
至关键字
While 关键字
有关键字
DownTo 关键字
向下
For variable := expression1 DownTo expression2 Do statement.
在For DownTo
其他
-
If condition then statement Else statement -
Try statement except exception Else statement end -
Case expression of Else end;
Elseifelsetry-exceptcaseelse
如果关键字
则关键字
尝试关键字
以关键字为例
结束
-
Begin statements End; -
Try statements Except Exception clauses... else Statements... End; -
Try statements Finally statements End; -
Case Expression of clauses Else statements... End;
EndCase
除
Try statements Except statements End;
使用Try-ExceptOnExceptRaise
Try X := Y/Z; Except Raise('A divide by zero error!'); End;
最后
Try statements... Finally statements... End;
finallytry-finallytryfinallytry-finally
结束关键字
Raise 关键字
尝试关键字
对于
-
for variable := expression1 to expression2 do statement -
for variable := expression1 downto expression2 do statement
for
For i := 0 to AnIndex - 1 Do Begin S := S + #13 + AString; End; ShowMessage(S);
做关键字
DownTo 关键字
重复关键字
To 关键字
While 关键字
使用关键字
转发
subroutine header; forward;
Forwardforward
功能
Function name (parameters) : return type;
Function
Function TestFunc(Min, Max : integer) : integer; Begin Result := Random(Max - Min +1); End;
后藤
goto label
goto
Label StartHere; // code StartHere: //do anything; Goto StartHere;
标签关键字
如果
-
if condition then statement; -
if condition then statement1 else statement2;
IfElse
如果 A > B 那么 ShowMessage('X>Y and A > B'); 否则 ShowMessage('X>Y and A =B'); End;
And 关键字
开始关键字
Or 关键字
然后关键字
Else 关键字
界面
接口
Interface
接口interface
接口可以看作是与计算机内存中现有对象的一个接触点,通过接口的属性提供读/写数据的能力。接口从其关联对象请求数据。
DelphiScript 是一种无类型语言,因此无法定义新类型(如新记录、数组或类)以及相关接口。
标签
label digits, identifier, ...;
labelgoto
Label StartHere; // code StartHere: //do anything; Goto StartHere;
转到关键字
模式
Integer expression mod integer expression
modA mod BA - (A div B) * B
除法函数
无
const nil = pointer(0);
nil
没有
-
not boolean expression -
not integer expression
notNot False = Truenot true = falsenot
的
case expression of
selector: expression1
...
end
Ofcase
案例声明
或者
-
boolean expression or boolean expression -
integer expression or integer expression
如果操作数是布尔类型,or
And 关键字
非关键字
Shl 关键字
Shr 关键字
Xor 关键字
程序
-
Procedure name; -
Procedure Name (Parameter, ...);
procedure
Procedure TestRand(Var Rand: Integer; Max : Integer); Begin Rand := Random(Max); End;
功能关键字
计划
Program Name;
declarations...
Block
program*.pas
功能关键字
提高
Raise statement;
raiseTryRaise
Raise(Format('Invalid Value Entered : %d', \[Height]));
请注意,DelphiScript 不支持OnException
重复
repeat
statements;
until boolean expression
Repeat Until
Repeat Write('Enter a value (0..9): '); ShowMessage(IntToStr(I)); Until (I >= 0) and (I = 9);
直到关键字
结果
Var result : Function return type;
脚本中的每个函数都必须使用Result
函数关键字
Shl
value shl bits
shlBits
和关键字
非关键字
或关键字
Shr 关键字
Xor 关键字
嘘声
value shr bits
shrBits
和关键字
非关键字
或关键字
Shl 关键字
Xor 关键字
字符串
-
type string; -
type Name = string[Constant]
string
那么
If expression then statement
ThenIf
如果关键字
至
For variable := expression1 to expression2 do statement
tofor
For i := 0 to AnIndex - 1 do S := S + #13 + AString;
尝试
-
Try statements finally statements end; -
Try statements except statements end;
trytry-excepttry-finally
无论控制如何离开 try 块异常、退出或断开,finallytry-finallytry-finally
Reset(F); Try ... // process file F Finally CloseFile(F); End;
使用try-exceptOnExceptRaise
Try X := Y/Z; Except Raise('A divide by zero error!'); End;
提高关键词
类型
Type Name = type declaration ...
Type
脚本中忽略了类型转换,因此变量声明中的类型会被忽略,可以跳过。因此,这些声明是正确的:
var a : integer;
var b : integer;
var c, d;
存储过程/函数声明中的参数类型会被忽略,可以跳过。例如,以下代码是正确的:
Function sum(a, b) : integer; Begin Result := a + b; End;
一般来说,变量可用于存储任何数据类型,并执行大量操作和类型转换。变体在运行时进行类型检查和计算。编译器不会对代码中可能出现的错误发出警告,这些错误只能通过大量测试才能发现。总的来说,使用变体的代码部分可被视为解释型代码,因为许多操作要到运行时才能解决。这会影响代码的运行速度。
Var V Begin // you can assign to it values of several different types: V := 10; V := 'Hello, World'; V := 45.55; End;
变量关键字
单位
-
Unit Name;
interface
declarations
implementation
declarations
statements
Initialization
statements
finalization
statements
end.
-
Unit Name;
interface
declarations
implementation
declarations
statements
begin
statements
end.
unit
直到
Repeat
Statements;
Until boolean expression
untilRepeat-UntilRepeat-Until
Repeat Write('Enter a value (0..9): '); ShowMessage(IntToStr(I)); Until (I >= 0) and (I = 9);
重复关键字
用途
Uses Unit Name, ...;
usesuses
存储在同一项目中的所有单元都可以访问这些单元中的全局变量。在同一项目中的单元中声明变量时,请牢记这一点。
Altium Designer 的 Client、PCB、Schematic 和 WorkSpace Manager API 以及 Delphi 的 SysUtils、Classes 和其他单元都已导入脚本并可在脚本中使用,因此无需在脚本中声明这些单元。
有关 Altium Designer API 的更多详细信息,请参阅使用 Altium Designer API文档。
变量
Name : Type
Name : Type = Expression;
脚本中的所有变量都是变量类型。类型转换被忽略。变量声明中的类型会被忽略,可以跳过,因此这些声明是正确的:
Var a : integer;
Var b : integer;
Var c, d;
过程/函数声明中的参数类型被忽略,可以跳过。例如,以下代码是正确的:
Function sum(a, b) : integer; Begin Result := a + b; End;
一般来说,变量可用于存储任何数据类型,并执行大量操作和类型转换。变体在运行时进行类型检查和计算。编译器不会对代码中可能出现的错误发出警告,这些错误只能通过大量测试才能发现。总的来说,使用变体的代码部分可被视为解释型代码,因为许多操作要到运行时才能解决。这会影响代码的运行速度。
声明变量:
Var V; Begin // you can assign to it values of several different types: V := 10; V := 'Hello, World'; V := 45.55; End;
数组元素的类型会被忽略,可以跳过,因此这些声明是等价的:
Var x : array [1..2] of double;
Var x : array [1..2];
Type
TVertices = Array [1..50] Of TLocation;
Var
NewVertices : TVertices;
Var
NewVertices : Array [1..50] of TLocation;
虽然
while expression do statement
while
Break 关键字
继续关键字
Do 关键字
DownTo 关键字
For 关键字
重复关键字
至关键字
使用关键字
与
with expression do statement
With
Form.Canvas.Pen.Width := 2; Form.Canvas.Pen.Color := clSilver;
With Form.Canvas.Pen do Begin Width := 2; Color := clSilver; End;
关键字
Xor
- 布尔表达式 Xor 布尔表达式
-
integer expression Xor integer expression
xor
整型运算符xor10