pascal_stmt.htm
来自「Delphi脚本控件」· HTM 代码 · 共 2,046 行 · 第 1/5 页
HTM
2,046 行
Parameters are passed to the script by reference.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>program</b></font> P(A, B);
<font color="blue"><b>begin</b></font>
<font color="blue"><b>print</b></font> A;
B := 100;
<font color="blue"><b>end</b></font>.
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Namespace Statements">Namespace Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Property Statements"><h3>Property Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
A property, like a field, defines an attribute of an object. But while a field is merely a storage location whose contents can be examined and changed, a property associates specific actions with reading or modifying its data. Properties provide control over access to an object抯 attributes, and they allow attributes to be computed.
<H4>
Grammar
</H4>
<blockquote>
<pre>
PropertyStmt -> <font color="blue"><b>property</b></font> Ident [ParamList]
( [read IdentRead] |
[write IdentWrite] )
Specifiers <font color="Red">';'</font>
[<font color="blue"><b>default</b></font>]<font color="Red">';'</font>
ParamList -> <font color="Red">'['</font> Param/<font color="Red">','</font>... <font color="Red">']'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Name of the property
</blockquote>
</blockquote>
<blockquote>
<i>Param</i>
<blockquote>
Optional. Parameter of indexed property
</blockquote>
</blockquote>
<blockquote>
<i>IdentRead, IdentWrite</i>
<blockquote>
Class members which represent read and write specifiers accordingly
</blockquote>
</blockquote>
<blockquote>
<i>Default</i>
<blockquote>
Optional. Specifies an indexed property which is array property. A class can have only one <font color="black"><i>default</i></font> property.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>class</b></font> TMyClass(TObject)
<font color="blue"><b>var</b></font>
fZ = [10, 20, 30, 40, 50];
<font color="blue"><b>function</b></font> GetElement(I);
<font color="blue"><b>begin</b></font>
result := fZ[I];
<font color="blue"><b>end</b></font>;
<font color="blue"><b>procedure</b></font> SetElement(I, Value);
<font color="blue"><b>begin</b></font>
fZ[I] := Value;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>property</b></font> Z[I] read GetElement write SetElement; <font color="blue"><b>default</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font> X = TMyClass.Create;
X[1] := 50;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Raise Statements"><h3>Raise Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Generates an error condition that can be handled by a try...except舊inally statement.
<H4>
Grammar
</H4>
<blockquote>
<pre>
RaiseStmt -> <font color="blue"><b>raise</b></font> [Ident] <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Optional. If <font color="black"><i>Ident</i></font> is ommited the statement re-raises the current
exception, otherwise <font color="black"><i>Ident</i></font> represents an exception object.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>try</b></font>
<font color="blue"><b>try</b></font>
<font color="blue"><b>raise</b></font> 100;
<font color="blue"><b>except</b></font>
<font color="blue"><b>on</b></font> E <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
<font color="blue"><b>print</b></font> <font color="Red">'except'</font>;
<font color="blue"><b>print</b></font> E;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>finally</b></font>
<font color="blue"><b>print</b></font> <font color="Red">'finally'</font>;
<font color="blue"><b>end</b></font>;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Try-except Statements">Try-except Statements</a></li>
<li><a href="#Try-finally Statements">Try-finally Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Record Statements"><h3>Record Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Creates a record type.
<H4>
Grammar
</H4>
<blockquote>
<pre>
RecordStmt -> <font color="blue"><b>record</b></font> Ident [ <font color="Red">'('</font> Ancestor <font color="Red">')'</font> ]
MemberStatement /...
<font color="blue"><b>end</b></font> <font color="Red">';'</font>
MemberStatement -> VarStmt |
FunctionStmt |
ProcedureStmt |
PropertyStatement |
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Name of the record type
</blockquote>
</blockquote>
<blockquote>
<i>Ancestor</i>
<blockquote>
Optional. Name of the <font color="black"><i>ancestor</i></font> record type.
</blockquote>
</blockquote>
<blockquote>
<i>MemberStatement</i>
<blockquote>
One or more statements that define the variables, properties, and methods of the record.
</blockquote>
</blockquote>
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>record</b></font>
X: Integer = Random(100);
Y: Integer = Random(100);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>record</b></font> TRandomCircle (TRandomPoint)
R: Integer = Random(100);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
C: TRandomCircle;
<font color="blue"><b>print</b></font> C;
</pre>
Method Initialize provides another way to initialize the record fields.
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>record</b></font>
X, Y: Integer;
<font color="blue"><b>procedure</b></font> Initialize;
<font color="blue"><b>begin</b></font>
X := Random(100);
Y := Random(100);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>record</b></font> TRandomCircle (TRandomPoint)
R: Integer;
<font color="blue"><b>procedure</b></font> Initialize;
<font color="blue"><b>begin</b></font>
R := Random(100);
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
C: TRandomCircle; // calls Initialize here
<font color="blue"><b>print</b></font> C;
</pre>
Use Type statement instead of the Record statement to provide native Object Pascal syntax for your scripts.
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<li><a href="#Function Statements">Function Statements</a></li>
<li><a href="#Procedure Statements">Procedure Statements</a></li>
<li><a href="#Property Statements">Property Statements</a></li>
<li><a href="#Var Statements">Var Statements</a></li>
<li><a href="#Type Statements">Type Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Repeat Statements"><h3>Repeat Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
<H4>
Grammar
</H4>
<blockquote>
<pre>
RepeatStmt -> <font color="blue"><b>repeat</b></font> Statement <font color="blue"><b>until</b></font> Condition <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Condition</i>
<blockquote>
A Boolean expression. If <font color="black"><i>condition</i></font> is undefined,
<font color="black"><i>condition</i></font> is treated as false.
</blockquote>
</blockquote>
<blockquote>
<i>Statement</i>
<blockquote>
A simple or structured <font color="black"><i>statement</i></font>.
</blockquote>
</blockquote>
The repeat <font color="black"><i>statement</i></font> executes its sequence of constituent statements
continually, testing <font color="black"><i>Condition</i></font> after each iteration. Whe <font color="black"><i>Condition</i></font> returns
True, the repeat <font color="black"><i>statement</i></font> terminates. The sequence is always executed at
least once because <font color="black"><i>Condition</i></font> is not evaluated until after the first
iteration.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>repeat</b></font>
K := I <font color="blue"><b>mod</b></font> J;
I := J;
J := K;
<font color="blue"><b>until</b></font> J = 0;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#For Statements">For Statements</a></li>
<li><a href="#While Statements">While Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Try-except Statements"><h3>Try-except Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Exceptions are handled within try...except statements.
<H4>
Grammar
</H4>
<blockquote>
<pre>
TryExceptStmt -> <font color="blue"><b>try</b></font>
TryStatements <font color="blue"><b>except</b></font>
ExceptionBlock
<font color="blue"><b>end</b></font> <font color="Red">';'</font>
ExceptionBlock -> ExceptStatements |
<font color="blue"><b>on</b></font> Ident <font color="blue"><b>do</b></font>
Statement/<font color="Red">','</font>...
[<font color="blue"><b>else</b></font> Statement] [<font color="Red">';'</font>]
<font color="blue"><b>end</b></font> <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>TryStatements</i>
<blockquote>
A sequence of statements (delimited by semicolons)
</blockquote>
</blockquote>
<blockquote>
<i>ExceptStatements</i>
<blockquote>
A sequence of statements (delimited by semicolons)
</blockquote>
</blockquote>
<blockquote>
<i>ExceptionBlock</i>
<blockquote>
Either another sequence of statements (<font color="black"><i>ExceptStatements</i></font>), or
a sequence of exception handlers, optionally followed by
else statements.
</blockquote>
</blockquote>
The <font color="black"><i>TryStatements</i></font> contain code where an error can occur,
while <font color="black"><i>ExceptionBlock</i></font> contain the code to handle any error that does
occur. If an error occurs in the <font color="black"><i>tryStatements</i></font>, program control is
passed to <font color="black"><i>ExceptionBlock</i></font> for processing. The initial value of exception
is the value of the error that occurred in <font color="black"><i>tryStatements</i></font>. If no
error occurs, <font color="black"><i>ExceptionBlock</i></font> are never executed.
If the error cannot be handled in the <font color="black"><i>ExceptionBlock</i></font> associated with the
<font color="black"><i>TryStatements</i></font> where the error occurred, use the raise statement to
propagate, or rethrow, the error to a higher-level error handler.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>try</b></font>
<font color="blue"><b>try</b></font>
<font color="blue"><b>raise</b></font> 100;
<font color="blue"><b>except</b></font>
<font color="blue"><b>on</b></font> E <font color="blue"><b>do</b></font>
<font color="blue"><b>begin</b></font>
<font color="blue"><b>print</b></font> <font color="Red">'except'</font>;
<font color="blue"><b>print</b></font> E;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
<font color="blue"><b>finally</b></font>
<font color="blue"><b>print</b></font> <font color="Red">'finally'</font>;
<font color="blue"><b>end</b></font>;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Raise Statements">Raise Statements</a></li>
<li><a href="#Try-finally Statements">Try-finally Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Try-finally Statements"><h3>Try-finally Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Sometimes you want to ensure that specific parts of an operation are completed, whether or not the operation is interrupted by an exception. In these situations, you can use a try...finally statement.
<H4>
Grammar
</H4>
<blockquote>
<pre>
TryFinallyStmt -> <font color="blue"><b>try</b></font>
TryStatements
<font color="blue"><b>finally</b></font>
FinallyStatements
<font color="blue"><b>end</b></font> <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>TryStatements</i>
<blockquote>
A sequence of statements (delimited by semicolons)
</blockquote>
</blockquote>
<blockquote>
<i>FinallyStatements</i>
<blockquote>
Optional. Statements that are unconditionally executed after all other error processing has occurred.
</blockquote>
</blockquote>
The try-finally statement executes the statements in <font color="black"><i>TryStatements</i></font>
(the try clause). If <font color="black"><i>TryStatements</i></font> finishes without raising exceptions,
<font color="black"><i>FinallyStatements</i></font> (the finally clause) is executed. If an exception is
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?