pascal_stmt.htm

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

HTM
2,046
字号
  Z := X;
  X := Y;
  Y := Z;
<font color="blue"><b>end</b></font>;
</pre>
</blockquote>
<a name="Const Statements"><h3>Const Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Creates new constants.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ConstStmt -> [<font color="blue"><b>const</b></font>] [<font color="Red">':'</font> TypeIdent] = Value /,... 
           <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Value</i>
<blockquote>
<font color="black"><i>Value</i></font> of constant.
</blockquote>
</blockquote>
<blockquote>
<i>TypeIdent</i>
<blockquote>
Type of constant
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>const</b></font> PI = 3.14;
</pre>
</blockquote>
<a name="Constructor Statements"><h3>Constructor Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
A constructor is a special method that creates and initializes instance objects.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ProcedureStmt -> <font color="blue"><b>constructor</b></font> Ident [<font color="Red">'('</font> FormalParm/<font color="Red">','</font>... <font color="Red">')'</font>] <font color="Red">';'</font>
                 <font color="blue"><b>begin</b></font>
                   Statement /<font color="Red">';'</font>...
                 <font color="blue"><b>end</b></font> <font color="Red">';'</font>    
FormalParm -> [<font color="blue"><b>var</b></font>] Parameter
</pre>
</blockquote>
The declaration of a constructor looks like a procedure declaration, but it begins with the word <b>constructor</b>.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>class</b></font> TPoint
  <font color="blue"><b>var</b></font> X, Y;
  <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>var</b></font>
  P = TPoint.Create;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<li><a href="#Procedure Statements">Procedure Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Continue Statements"><h3>Continue Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
The continue statement stops the current iteration of a loop, and starts 
a new iteration.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ContuinueStmt -> <font color="blue"><b>continue</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 statement to which continue applies. A local variable (declared in 
the block containing the for statement) without any qualifiers
</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>Continue</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="#Break Statements">Break 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="Delete Statements"><h3>Delete Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Destroys variable or its terminal
<H4>
Grammar
</H4>

<blockquote>
<pre>
DeleteStmt -> <font color="blue"><b>Delete</b></font> Expression [^]
</pre>
</blockquote>
</blockquote>



<a name="Enum statements"><h3>Enum statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Creates enumeration type.
<H4>
Grammar
</H4>
<blockquote>
<pre>
EnumStmt -> <font color="blue"><b>enum</b></font> <font color="Red">'('</font> Ident {<font color="Red">'='</font> Number} /<font color="Red">','</font>... <font color="Red">')'</font><font color="Red">';'</font>
</pre>
</blockquote>
Use Type statement instead of the Enum statement to provide native Object Pascal syntax for your scripts.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>enum</b></font> E (a, b = 10, c);
<font color="blue"><b>var</b></font> x: E;
<font color="blue"><b>print</b></font> x.a;
<font color="blue"><b>print</b></font> x.b;
<font color="blue"><b>print</b></font> x.c;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Type Statements">Type Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Exit Statements"><h3>Exit Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Exits from the current procedure.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ExitStmt -> <font color="blue"><b>exit</b></font> <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Break Statements">Break Statements</a></li>
<li><a href="#Continue Statements">Continue Statements</a></li>
<li><a href="#Halt Statements">Halt Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="For Statements"><h3>For Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
A for statement, unlike a repeat or while statement, requires you to specify explicitly the number 
of iterations you want the loop to go through.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ForStmt -> <font color="blue"><b>for</b></font> Counter <font color="Red">':='</font> InitialValue (<font color="blue"><b>to</b></font>|<font color="blue"><b>downto</b></font>) FinalValue <font color="blue"><b>do</b></font> 
             Statement
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Counter</i>
<blockquote>
Numeric variable used as a loop <font color="black"><i>counter</i></font>. The variable can't be an array element or an element of 
a user-defined type.
</blockquote>
</blockquote>
<blockquote>
<i>InitialValue</i>
<blockquote>
Initial value of <font color="black"><i>Counter</i></font>.
</blockquote>
</blockquote>
<blockquote>
<i>FinalValue</i>
<blockquote>
Final value of <font color="black"><i>Counter</i></font>
</blockquote>
</blockquote>
<blockquote>
<i>Statement</i>
<blockquote>
A simple or structured <font color="black"><i>statement</i></font> that does not change the value of <font color="black"><i>Counter</i></font>.
</blockquote>
</blockquote>
The for <font color="black"><i>statement</i></font> assigns the value of <font color="black"><i>InitialValue</i></font> to <font color="black"><i>Counter</i></font>, then 
 executes <font color="black"><i>statement</i></font> repeatedly, incrementing or decrementing <font color="black"><i>Counter</i></font>
 after each iteration. (The for...to syntax increments <font color="black"><i>Counter</i></font>, while
 the for...downto syntax decrements it.) When <font color="black"><i>Counter</i></font> returns the 
 same value as <font color="black"><i>FinalValue</i></font>, <font color="black"><i>statement</i></font> is executed once more and the 
 for <font color="black"><i>statement</i></font> terminates. In other words, <font color="black"><i>statement</i></font> is executed 
 once for every value in the range from <font color="black"><i>InitialValue</i></font> to <font color="black"><i>FinalValue</i></font>. 
 If <font color="black"><i>InitialValue</i></font> is equal to <font color="black"><i>FinalValue</i></font>, <font color="black"><i>statement</i></font> is executed exactly 
 once. If <font color="black"><i>InitialValue</i></font> is greater than <font color="black"><i>FinalValue</i></font>
 in a for...to <font color="black"><i>statement</i></font>, or less than <font color="black"><i>FinalValue</i></font> in a for...downto 
 <font color="black"><i>statement</i></font>, then <font color="black"><i>statement</i></font> is never executed.
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>for</b></font> I := 2 <font color="blue"><b>to</b></font> 63 <font color="blue"><b>do</b></font>
  <font color="blue"><b>if</b></font> Data[I] > Max <font color="blue"><b>then</b></font>
    Max := Data[I];
</pre>
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>for</b></font> I := ListBox1.Items.Count - 1 <font color="blue"><b>downto</b></font> 0 <font color="blue"><b>do</b></font>
  ListBox1.Items[I] := UpperCase(ListBox1.Items[I]);
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Repeat Statements">Repeat Statements</a></li>
<li><a href="#While Statements">While Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Function Statements"><h3>Function Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Declares the name, arguments, and code that form the body of a function.
<H4>
Grammar
</H4>
<blockquote>
<pre>
FunctionStmt -> [<font color="blue"><b>class</b></font>] <font color="blue"><b>function</b></font> Ident [<font color="Red">'('</font> FormalParam/<font color="Red">','</font>... <font color="Red">')'</font>] <font color="Red">';'</font> 
    [[call_convention] <font color="blue"><b>external</b></font> DllName [name FuncName]<font color="Red">';'</font>]
                <font color="blue"><b>begin</b></font>
                  Statement /<font color="Red">';'</font>...
                <font color="blue"><b>end</b></font> <font color="Red">';'</font>     
FormalParam -> [<font color="blue"><b>var</b></font>] Parameter
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
The name of the function.
</blockquote>
</blockquote>
<blockquote>
<i>Parameter</i>
<blockquote>
Represents formal <font color="black"><i>parameter</i></font> of function. The var keyword indicates that the 
argument is passed by reference.
</blockquote>
</blockquote>
<blockquote>
<i>Statement</i>
<blockquote>
Any simple or structured <font color="black"><i>statement</i></font>.
</blockquote>
</blockquote>
<blockquote>
<i>Class</i>
<blockquote>
Optional. The <font color="black"><i>class</i></font> keyword specifies a static (shared) method of a <font color="black"><i>class</i></font>. Can be used only inside of a <font color="black"><i>class</i></font> body.
</blockquote>
</blockquote>
<blockquote>
<i>call_convention</i>
<blockquote>
One of: pascal, cdecl, stdcall, register, safecall.
</blockquote>
</blockquote>
Special variable Result holds the function's return value.
<p></p>
Functions and procedures can be nested.
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>function</b></font> Fact(N: Integer): Integer;
<font color="blue"><b>begin</b></font>
  <font color="blue"><b>if</b></font> N = 1 <font color="blue"><b>then</b></font>
     result := 1
   <font color="blue"><b>else</b></font>
     result := N * Fact(N - 1); 
   <font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
</pre>
You can use the function <font color="black"><i>statement</i></font> inside of a <font color="black"><i>class</i></font> body. In such case the <font color="black"><i>statement</i></font> declares a method of the <font color="black"><i>class</i></font>.
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>class</b></font> TMyClass(TObject)
  Z: <font color="blue"><b>String</b></font> = <font color="Red">'abc'</font>; 
  <font color="blue"><b>function</b></font> DoubleZ: <font color="blue"><b>String</b></font>;
  <font color="blue"><b>begin</b></font>
    result := Z + Z;
  <font color="blue"><b>end</b></font>;
  <font color="blue"><b>class</b></font> <font color="blue"><b>function</b></font> Hello: <font color="blue"><b>String</b></font>;
  <font color="blue"><b>begin</b></font>
    result := <font color="Red">'Hello '</font> + ClassName;
  <font color="blue"><b>end</b></font>;
<font color="blue"><b>end</b></font>;
</pre>
<H4>
Example 3
</H4>
<pre>
<font color="blue"><b>const</b></font>
  DllName = <font color="Red">'TestDll.dll'</font>;
<font color="blue"><b>function</b></font> Min(X, Y: Integer): Integer; <font color="blue"><b>stdcall</b></font>; <font color="blue"><b>external</b></font> DllName name Min;
<font color="blue"><b>function</b></font> Max(X, Y: Integer): Integer; <font color="blue"><b>stdcall</b></font>; <font color="blue"><b>external</b></font> DllName;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<li><a href="#Procedure Statements">Procedure Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Goto Statements"><h3>Goto Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Transfers program execution to a labeled statement.
<H4>
Grammar
</H4>
<blockquote>
<pre>
GotoStmt -> <font color="blue"><b>goto</b></font> <font color="blue"><b>Label</b></font> <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Label</i>
<blockquote>
A unique identifier used when referring to the labeled statement.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>for</b></font> I:=1 <font color="blue"><b>to</b></font> 10 <font color="blue"><b>do</b></font>

⌨️ 快捷键说明

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