pascal_stmt.htm

来自「Delphi脚本控件」· HTM 代码 · 共 2,046 行 · 第 1/5 页

HTM
2,046
字号
<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H3>
paxPascal Statements
</H3>
<hr>
<ul>
<li><a href="#Assignment Statements">Assignment Statements</a></li>
<li><a href="#Break Statements">Break Statements</a></li>
<li><a href="#Case Statements">Case Statements</a></li>
<li><a href="#Class Statements">Class Statements</a></li>
<li><a href="#Compound Statements">Compound Statements</a></li>
<li><a href="#Const Statements">Const Statements</a></li>
<li><a href="#Constructor Statements">Constructor Statements</a></li>
<li><a href="#Continue Statements">Continue Statements</a></li>
<li><a href="#Delete Statements">Delete Statements</a></li>
<li><a href="#Enum statements">Enum statements</a></li>
<li><a href="#Exit Statements">Exit Statements</a></li>
<li><a href="#For Statements">For Statements</a></li>
<li><a href="#Function Statements">Function Statements</a></li>
<li><a href="#Goto Statements">Goto Statements</a></li>
<li><a href="#Halt Statements">Halt Statements</a></li>
<li><a href="#If Statements">If Statements</a></li>
<li><a href="#Label statements">Label statements</a></li>
<li><a href="#Labeled Statements">Labeled Statements</a></li>
<li><a href="#Namespace Statements">Namespace Statements</a></li>
<li><a href="#Print Statements">Print Statements</a></li>
<li><a href="#Procedure Statements">Procedure Statements</a></li>
<li><a href="#Program Statements">Program Statements</a></li>
<li><a href="#Property Statements">Property Statements</a></li>
<li><a href="#Raise Statements">Raise Statements</a></li>
<li><a href="#Record Statements">Record Statements</a></li>
<li><a href="#Repeat Statements">Repeat Statements</a></li>
<li><a href="#Try-except Statements">Try-except Statements</a></li>
<li><a href="#Try-finally Statements">Try-finally Statements</a></li>
<li><a href="#Type Statements">Type Statements</a></li>
<li><a href="#Unit Statements">Unit Statements</a></li>
<li><a href="#Uses Statements">Uses Statements</a></li>
<li><a href="#Var Statements">Var Statements</a></li>
<li><a href="#While Statements">While Statements</a></li>
<li><a href="#With Statements">With Statements</a></li>
<//ul>
<a name="Assignment Statements"><h3>Assignment Statements</h3></a>
<!-------------------------------------------------------------------->

<H4>
Grammar
</H4>

<blockquote>
<pre>
[<font color="blue"><b>Reduced</b></font>] ['@'] Expr1 ['^'] := ['@'] Expr2 ['^'] ';'
</pre>
</blockquote>
The reduced modifier is used to avoid a memory leak.


The reduced assignment 

<blockquote>
<pre>
<font color="blue"><b>reduced</b></font> A := E;
</pre>
</blockquote>

means

<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> temp := E;
E := <font color="blue"><b>nil</b></font>;
<font color="blue"><b>delete</b></font> A;
A := temp;
</pre>
</blockquote>


if A is array and E is element of A. Otherwise it means:

<blockquote>
<pre>
<font color="blue"><b>delete</b></font> A;
A := E;
</pre>
</blockquote>

<p>
The ^ at the left part of the assignment statement should be used only when Expr1 is alias and 
@ is presented at the right part of the statement.  
(Because Expr1 ^ = Expr2 
produces the same assignment as Expr1 = Expr2 in all another cases). When @ is presented at the right 
part, the use of ^ in the left part allows you to assign alias of Expr2 to terminal of Expr1. For 
example:


<blockquote>
<pre>
<font color="blue"><b>var</b></font> A[10], B, C, P;
B := 300;
C := 500;
P := @ A[5];
P^ := @ B;
writeln(P);
writeln(A[5]);
P := @ C;
writeln(A[5]);
writeln(P);
</pre>
</blockquote>

It produces

<blockquote>
<pre>
300
300
300
500
</pre>
</blockquote>

The ^ at the left part of the assignment statement should be used only when Expr2 is an alias.
In this case, the use of ^ allows you to assign Expr1 as alias of terminal of Expr2. For example

<blockquote>
<pre>
<font color="blue"><b>var</b></font> P1 = <font color="Red">"X"</font>;
<font color="blue"><b>var</b></font> P2 = <font color="Red">"Y"</font>;
<font color="blue"><b>var</b></font> T1 = [<font color="Red">"R"</font>, [<font color="Red">"F"</font>, @ P1]];
<font color="blue"><b>var</b></font> T2 = [<font color="Red">"R"</font>, @ P2];
<font color="blue"><b>var</b></font> Q1 = @ T1[1];
<font color="blue"><b>var</b></font> Q2 = @ T2[1];
Q2^ := @ Q1^;
</pre>
</blockquote>


This example illustrates how the search of most general unifier works (mechanical theorem proving). 
T1 and T2 represent terms, P1 and P2 are parameters of T1 and T2 accordingly. The last statement 

<blockquote>
<pre>
Q2^ := @ Q1^;
</pre>
</blockquote>

changes parameters, not source terms. 

<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Dim Statements">Dim Statements</a></li>
<//ul>
</blockquote>
</blockquote>



<a name="Break Statements"><h3>Break Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Executing the break statement exits from the current loop or statement, and begins script execution
<H4>
Grammar
</H4>
<blockquote>
<pre>
BreakStmt -> <font color="blue"><b>break</b></font> [<font color="blue"><b>Label</b></font>] <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Label</i>
<blockquote>
Optional. Specifies the <font color="black"><i>label</i></font> of the statement you are breaking from.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
L: <font color="blue"><b>for</b></font> I:=1 <font color="blue"><b>to</b></font> 10 <font color="blue"><b>do</b></font>
     <font color="blue"><b>for</b></font> J:=1 <font color="blue"><b>to</b></font> 5 <font color="blue"><b>do</b></font>
       <font color="blue"><b>if</b></font> J = 3 <font color="blue"><b>then</b></font>
         <font color="blue"><b>Break</b></font> L
       <font color="blue"><b>else</b></font>
         writeln(I, <font color="Red">' '</font>, J);
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Continue Statements">Continue Statements</a></li>
<li><a href="#Exit Statements">Exit Statements</a></li>
<li><a href="#Halt Statements">Halt Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Case Statements"><h3>Case Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
The case statement provides a readable alternative to complex nested 
if conditionals.
<H4>
Grammar
</H4>
<blockquote>
<pre>
CaseStmt -> <font color="blue"><b>case</b></font> SelectorExpression <font color="blue"><b>of</b></font>
            CaseSelector/<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>
CaseSelector -> CaseLabel/<font color="Red">','</font>... <font color="Red">':'</font> Statement
CaseLabel -> ConstExpr [<font color="Red">'..'</font> ConstExpr]
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>SelectorExpression</i>
<blockquote>
Any numeric or string expression.
</blockquote>
</blockquote>
<blockquote>
<i>CaseSelector</i>
<blockquote>
One of the following:
<ul type="circle">
	<li>a numeral constant, or other expression that the
        compiler can evaluate without executing your program.   
    </li>
	<li>
	    a subrange having the form First..Last, where First and Last
        both satisfy the criterion above and First is less than or 
        equal to Last
	</li>
	<li>
        a list having the form item1, ..., itemn, where each item 
        satisfies one of the criteria above
	</li>
</ul>
</blockquote>
</blockquote>
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>case</b></font> MyColor <font color="blue"><b>of</b></font>
  Red: X := 1;
  Green: X := 2;
  Blue: X := 3;
  Yellow, Orange, Black: X := 0;
<font color="blue"><b>end</b></font>;
</pre>
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>case</b></font> Selection <font color="blue"><b>of</b></font>
  Done: Form1.Close;
  Compute: CalculateTotal(UnitCost, Quantity);
<font color="blue"><b>else</b></font>
  Beep;
<font color="blue"><b>end</b></font>;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#If Statements">If Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Class Statements"><h3>Class Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ClassStmt -> <font color="blue"><b>class</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 ->  ConstructorStmt | 
                    VarStmt |
                    FunctionStmt |
                    ProcedureStmt |
                    PropertyStatement |
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Name of the class.
</blockquote>
</blockquote>
<blockquote>
<i>Ancestor</i>
<blockquote>
Optional. Name of the <font color="black"><i>ancestor</i></font> class.
</blockquote>
</blockquote>
<blockquote>
<i>MemberStatement</i>
<blockquote>
One or more statements that define the variables, properties, and methods of the class.
</blockquote>
</blockquote>
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>class</b></font> TPoint
  X, Y: Double;
  <font color="blue"><b>constructor</b></font> Create(X, Y);
  <font color="blue"><b>begin</b></font>
    Self.X := X;
    Self.Y := Y;
  <font color="blue"><b>end</b></font>; 
<font color="blue"><b>end</b></font>;

<font color="blue"><b>class</b></font> TCircle(TPoint)
  R: Double;
  <font color="blue"><b>constructor</b></font> Create(X, Y, R);
  <font color="blue"><b>begin</b></font>
    <font color="blue"><b>inherited</b></font> Create(X, Y);
    Self.R := R;
  <font color="blue"><b>end</b></font>; 
<font color="blue"><b>end</b></font>;
</pre>
All constructors must have name Create.
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>var</b></font>
  Point = TPoint.Create(3, 5), Circle = TCircle.Create(3, 5, 7);
</pre>
Classes can have static (shared) members. The definition of a static member must begin with the 
reserved word class. For example,
<H4>
Example 3
</H4>
<pre>
<font color="blue"><b>class</b></font> TFoo(TObject)
  <font color="blue"><b>class</b></font> <font color="blue"><b>var</b></font> X: <font color="blue"><b>String</b></font>;
  <font color="blue"><b>class</b></font> <font color="blue"><b>function</b></font> F(): Integer;
  <font color="blue"><b>begin</b></font>
    result := 23;
  <font color="blue"><b>end</b></font>;
  <font color="blue"><b>class</b></font> <font color="blue"><b>procedure</b></font> P();
  <font color="blue"><b>begin</b></font>
    <font color="blue"><b>print</b></font> X;
  <font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
</pre>
Here X, F and P are static members of class TFoo.
Use Type statement instead of the Class statement to provide native Object Pascal syntax for your scripts.
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Constructor Statements">Constructor 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="#Record Statements">Record Statements</a></li>
<li><a href="#Type Statements">Type Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Compound Statements"><h3>Compound Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
A compound statement is a sequence of other (simple or structured) 
statements to be executed in the order in which they are written.
<H4>
Grammar
</H4>
<blockquote>
<pre>
CompoundStmt -> <font color="blue"><b>begin</b></font> Statement /<font color="Red">';'</font>... <font color="blue"><b>end</b></font>
</pre>
</blockquote>
The compound statement is bracketed by the reserved words <b>begin</b> and 
<b>end</b>, and its constituent statements are separated by semicolons.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>begin</b></font>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?