c_stmt.htm

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

HTM
1,345 行
字号
</H4>
<blockquote>
<pre>
StructureStmt -> <font color="blue"><b>structure</b></font> Ident [<font color="Red">':'</font> Ancestor] <font color="Red">'{'</font>
                 MemberStatement /...
                 <font color="Red">'}'</font>
		 
MemberStatement ->  VarStmt |
                    FunctionStmt |
                    PropertyStmt |
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Name of structure
</blockquote>
</blockquote>
<blockquote>
<i>Ancestor</i>
<blockquote>
Optional. Name of <font color="black"><i>ancestor</i></font> structure type.
</blockquote>
</blockquote>
<blockquote>
<i>MemberStatement</i>
<blockquote>
One or more statements that define the variables, properties, and methods of the structure.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>structure</b></font> RandomPoint {
  <font color="blue"><b>int</b></font> X = random(0, 100);
  <font color="blue"><b>int</b></font> y = random(0, 100);
}
<font color="blue"><b>structure</b></font> RandomCircle: RandomPoint {
  <font color="blue"><b>int</b></font> R = random (0, 100);
}

RandomCircle C;
<font color="blue"><b>print</b></font> C;
</pre>
</blockquote>
<a name="Switch Statements"><h3>Switch Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Enables the execution of one or more statements when a specified expression's value matches a label.
<H4>
Grammar
</H4>
<blockquote>
<pre>
SwitchStmt -> <font color="blue"><b>switch</b></font> <font color="Red">'('</font> Expression <font color="Red">')'</font> <font color="Red">'{'</font>
                <font color="blue"><b>case</b></font> Label <font color="Red">':'</font>
                  StatementList /...
                [<font color="blue"><b>default</b></font> <font color="Red">':'</font>
                  StatementList]
              <font color="Red">'}'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Expression</i>
<blockquote>
The <font color="black"><i>expression</i></font> to be evaluated.
</blockquote>
</blockquote>
<blockquote>
<i>Label</i>
<blockquote>
An identifier to be matched against <font color="black"><i>expression</i></font>. If <font color="black"><i>label</i></font> equal to <font color="black"><i>Expression</i></font>, execution starts with the <font color="black"><i>StatementList</i></font> immediately after the colon, and continues until it encounters either a break statement, which is optional, or the end of the switch statement.
</blockquote>
</blockquote>
<blockquote>
<i>StatementList</i>
<blockquote>
One or more statements to be executed.
</blockquote>
</blockquote>
<blockquote>
<i>default</i>
<blockquote>
Optional. Provides a statement to be executed if none of the <font color="black"><i>label</i></font> values matches <font color="black"><i>expression</i></font>. It can appear anywhere within the switch code block.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>switch</b></font> (P) {
  <font color="blue"><b>case</b></font> 1: 
    <font color="blue"><b>print</b></font> <font color="Red">'one'</font>;
    <font color="blue"><b>break</b></font>;
  <font color="blue"><b>case</b></font> 2: 
  <font color="blue"><b>case</b></font> 3: 
  <font color="blue"><b>case</b></font> 4: 
  <font color="blue"><b>case</b></font> 5: 
    <font color="blue"><b>print</b></font> <font color="Red">'two'</font>;
    <font color="blue"><b>break</b></font>;
  <font color="blue"><b>default</b></font>: <font color="blue"><b>print</b></font> <font color="Red">'three'</font>;
}
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#If Statements">If Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Throw Statements"><h3>Throw Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Generates an error condition that can be handled by a try...catch協inally statement.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ThrowStmt -> <font color="blue"><b>throw</b></font> [Ident] <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Any expression.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>try</b></font> {
  <font color="blue"><b>throw</b></font> 100;
}
<font color="blue"><b>catch</b></font> (e) {  
  <font color="blue"><b>print</b></font> <font color="Red">'catch'</font>;
  <font color="blue"><b>print</b></font> e;
}
<font color="blue"><b>finally</b></font> {  
  <font color="blue"><b>print</b></font> <font color="Red">'finally'</font>;
}
<font color="blue"><b>print</b></font> <font color="Red">'here'</font>;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Try Statements">Try Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Try Statements"><h3>Try Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Implements error handling.
<H4>
Grammar
</H4>
<blockquote>
<pre>
TryStmt -> <font color="blue"><b>try</b></font> <font color="Red">'{'</font>
             TryStatements <font color="Red">'}'</font>
           <font color="blue"><b>catch</b></font> <font color="Red">'('</font> E <font color="Red">')'</font> <font color="Red">'{'</font>
             CatchStatements <font color="Red">'}'</font>
           <font color="blue"><b>finally</b></font> <font color="Red">'{'</font>
             FinallyStatements <font color="Red">'}'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>TryStatements</i>
<blockquote>
Required. Statements where an error can occur.
</blockquote>
</blockquote>
<blockquote>
<i>CatchStatements</i>
<blockquote>
Optional. Statements to handle errors occurring in the associated <font color="black"><i>TryStatements</i></font>.
</blockquote>
</blockquote>
<blockquote>
<i>FinallyStatements</i>
<blockquote>
Optional. Statements that are unconditionally executed after all other error processing has occurred.
</blockquote>
</blockquote>
The <font color="black"><i>TryStatements</i></font> contain code where an error can occur, while <font color="black"><i>CatchStatements</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>CatchStatements</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>CatchStatements</i></font> are never executed.
<H4>
Example
</H4>
<pre>
<font color="blue"><b>try</b></font> {
  <font color="blue"><b>throw</b></font> 100;
}
<font color="blue"><b>catch</b></font> (e) {  
  <font color="blue"><b>print</b></font> <font color="Red">'catch'</font>;
  <font color="blue"><b>print</b></font> e;
}
<font color="blue"><b>finally</b></font> {  
  <font color="blue"><b>print</b></font> <font color="Red">'finally'</font>;
}
<font color="blue"><b>print</b></font> <font color="Red">'here'</font>;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Throw Statements">Throw Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Using Statements"><h3>Using Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Using statements are provided to facilitate the use of namespaces.
<H4>
Grammar
</H4>
<blockquote>
<pre>
UsingStmt -> <font color="blue"><b>using</b></font> NamespaceName, /<font color="Red">','</font>... <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>using</b></font> StdCtrls, Forms;
<font color="blue"><b>var</b></font>
  F = <font color="blue"><b>new</b></font> TForm(NULL),
  B = <font color="blue"><b>new</b></font> TButton(F);

F.Show();
B.Parent = F;
B.OnClick = & AHandler;
B.Caption = <font color="Red">'Click Me'</font>;

<font color="blue"><b>function</b></font> AHandler(Sender){
  <font color="blue"><b>print</b></font> <font color="Red">'You have clicked the button'</font>;
}
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Namespace Statements">Namespace Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Var Statements"><h3>Var Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Declares a variable.
<H4>
Grammar
</H4>
<blockquote>
<pre>
VarStmt -> [<font color="blue"><b>static</b></font>] [<font color="blue"><b>var</b></font>] [TypeName] Variable [<font color="Red">'['</font>Subscripts<font color="Red">']'</font>] [ = Value ] /,... <font color="Red">';'</font>
Subscripts -> Upperbound /<font color="Red">','</font>...
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Variable</i>
<blockquote>
The name of the <font color="black"><i>variable</i></font> being declared.
</blockquote>
</blockquote>
<blockquote>
<i>Value</i>
<blockquote>
The initial <font color="black"><i>value</i></font> assigned to the <font color="black"><i>variable</i></font>
</blockquote>
</blockquote>
<blockquote>
<i>static</i>
<blockquote>
Optional. The <font color="black"><i>static</i></font> keyword specifies a <font color="black"><i>static</i></font> (shared) field of a class. Can be used only inside of a class body.
</blockquote>
</blockquote>
<blockquote>
<i>Subscripts</i>
<blockquote>
Dimensions of an array <font color="black"><i>variable</i></font>.
</blockquote>
</blockquote>
<blockquote>
<i>Upperbound</i>
<blockquote>
Upper bound. The lower bound of an array is always zero.
</blockquote>
</blockquote>
Use the var statement to declare variables. These variables can be assigned values at declaration or later in your script.
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>var</b></font> A(30, 4);
<font color="blue"><b>var</b></font> X = [10, 20, 30];
<font color="blue"><b>var</b></font> Y;
<font color="blue"><b>var</b></font> Z = <font color="blue"><b>new</b></font> TObject();
</pre>
You can use the var statement inside of a class body. In such case the statement declares a field of a class instance or a <font color="black"><i>static</i></font> (shared) field of the class.
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>class</b></font> MyClass
  <font color="blue"><b>var</b></font> A(10, 2), X;  
  <font color="blue"><b>var</b></font> Y = [100, 200, 300];
  <font color="blue"><b>static</b></font> <font color="blue"><b>var</b></font> Z = 5;
  <font color="blue"><b>function</b></font> MyClass(){}
end;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="While Statements"><h3>While Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
The while statement executes its constituent statement repeatedly, testing Condition 
expression before each iteration. As long as 
Condition returns True, execution continues.
<H4>
Grammar
</H4>
<blockquote>
<pre>
WhileStmt -> <font color="blue"><b>while</b></font> <font color="Red">'('</font> Condition <font color="Red">')'</font>
               Statement
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Condition</i>
<blockquote>
A Boolean expression. If <font color="black"><i>condition</i></font> is null or undefined, <font color="black"><i>condition</i></font> is treated as false.
</blockquote>
</blockquote>
<blockquote>
<i>Statement</i>
<blockquote>
The <font color="black"><i>statement</i></font> to be executed if <font color="black"><i>Condition</i></font> is true. Can be a compound <font color="black"><i>statement</i></font>
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>while</b></font> (Data[I] <> X) ++I;
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Do Statements">Do Statements</a></li>
<li><a href="#For Statements">For Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="With Statements"><h3>With Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
The with statement is a shorthand for referencing the 
the fields, properties, and methods of an object.
<H4>
Grammar
</H4>
<blockquote>
<pre>
WithStmt -> <font color="blue"><b>with</b></font> <font color="Red">'('</font> Obj/<font color="Red">','</font>... <font color="Red">')'</font> Statement
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Obj</i>
<blockquote>
A variable reference denoting an object
</blockquote>
</blockquote>
<blockquote>
<i>Statement</i>
<blockquote>
Any simple or compound <font color="black"><i>statement</i></font>.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>with</b></font> (Form1) {
  Caption = <font color="Red">'My Form'</font>;
  Height = 200;
  Width = 300;
}
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Class Statements">Class Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<p>
<HR>
<font size = 1 color ="gray">
Copyright &copy; 1999-2005
VIRT Laboratory. All rights reserved.
</font>
</body>
</html>

⌨️ 快捷键说明

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