pascal_features.htm

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

HTM
824
字号
<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>

<h3>
paxPascal Features
</h3>
<hr>

<ul>
<li><a href="#Program Structure">Program Structure</a>
<li><a href="#Declaration of Variables">Declaration of Variables</a>
<li><a href="#Class Types">Class Types</a>
<li><a href="#Record Types">Record Types</a>
<li><a href="#Array Types">Array Types</a>
<li><a href="#Namespaces">Namespaces</a>
<li><a href="#Regular Expressions">Regular Expressions</a>
<li><a href="#Strings">Strings</a>
<li><a href="#Forward Declarations">Forward Declarations</a>
<li><a href="#Control Structures">Control Structures</a>
<li><a href="#Embedding scripts into html pages">Embedding Scripts into Html Pages</a>
<li><a href="#Operator Overloading">Operator Overloading</a>
<li><a href="#LISPPA">LISPPA</a>
<li><a href="#Syntax">Syntax</a>
</ul>

<p>


paxPascal implements a subset of Object Pascal. For example, the following script is admissible:

<blockquote>
<pre>
<font color="blue"><b>program</b></font> P;
<font color="blue"><b>type</b></font>
  TMyClass = <font color="blue"><b>class</b></font>;

  TMyArray = <font color="blue"><b>array</b></font>[1..3] <font color="blue"><b>of</b></font> <font color="blue"><b>String</b></font>;

  TMyClass = <font color="blue"><b>class</b></font>(TObject)
  <font color="blue"><b>private</b></font>
    <font color="blue"><b>function</b></font> GetProp: Integer;
  <font color="blue"><b>public</b></font>
    <font color="blue"><b>function</b></font> MyFunc(U: Integer; V: Integer): Integer;
    <font color="blue"><b>procedure</b></font> MyProc;
    <font color="blue"><b>property</b></font> MyProp: Integer read GetProp;
  <font color="blue"><b>end</b></font>;

  TMyRec = <font color="blue"><b>record</b></font>
    X, Y: Integer;
  <font color="blue"><b>end</b></font>;

<font color="blue"><b>function</b></font> GlobalFunc: Integer; forward;

<font color="blue"><b>function</b></font> TMyClass.MyFunc(U: Integer; V: Integer): Integer;
<font color="blue"><b>begin</b></font>
  result := U + V + GlobalFunc;
<font color="blue"><b>end</b></font>;

<font color="blue"><b>procedure</b></font> TMyClass.MyProc;
<font color="blue"><b>begin</b></font>
  writeln('here');
<font color="blue"><b>end</b></font>;

<font color="blue"><b>function</b></font> TMyClass.GetProp: Integer;
<font color="blue"><b>begin</b></font>
  result := 11;
<font color="blue"><b>end</b></font>;

<font color="blue"><b>function</b></font> GlobalFunc: Integer;
<font color="blue"><b>begin</b></font>
  result := 700;
<font color="blue"><b>end</b></font>;

<font color="blue"><b>var</b></font>
  X: TMyClass;
  A: TMyArray;
  R: TMyRec;
<font color="blue"><b>begin</b></font>
  X := TMyClass.Create;
  A[1] := 'abc';
  A[2] := 'pqr';
  A[3] := 'uv';
  R.X := 100; 
  writeln(X.MyFunc(4, 5));
  X.MyProc;
  writeln(X.MyProp);
  writeln(R.X);
<font color="blue"><b>end</b></font>;
</pre>
</blockquote>


<p>From another hand, paxPascal has a few extra features which are absent in the Object Pascal.


<a name="Program Structure">
<h4>
Program Structure
</h4>

<p>
A paxPascal program is the list of statements. In this relation, paxPascal is more similar with 
VBScript or JavaScript. 
</p>

<p>
For example, the following script

<blockquote>
<pre>
<font color="blue"><b>program</b></font> P;
<font color="blue"><b>type</b></font>
  TMyRec = <font color="blue"><b>record</b></font>
    X, Y: Integer;
  <font color="blue"><b>end</b></font>;
<font color="blue"><b>var</b></font>
  R: TMyRec;
<font color="blue"><b>begin</b></font>
  <font color="blue"><b>print</b></font> R;
<font color="blue"><b>end</b></font>.
</pre>
</blockquote>

contains <b>four</b> executable statements:

<ol>

<li>
<pre>
<font color="blue"><b>program</b></font> P;
</pre>
Creates namespace P.
<p>
</li>

<li>
<pre>
<font color="blue"><b>type</b></font>
  TMyRec = <font color="blue"><b>record</b></font>
    X, Y: Integer;
  <font color="blue"><b>end</b></font>;
</pre>
Creates record type TMyRec.
<p>
</li>

<li>
<pre>
<font color="blue"><b>var</b></font>
  R: TMyRec;
</pre>
Creates variable R.
<p>
</li>

<li>
<pre>
  <font color="blue"><b>print</b></font> R;
</pre>
Printes variable R.
<p>
</li>

</ol>


<a name="Declaration of Variables">
<h4>
Declaration of Variables
</h4>

<ul>

<li>
You can omit declaration of a variable. In such case, the variable obtains Variant type.
For example, the following script   

<blockquote>
<pre>
<font color="blue"><b>function</b></font> MyFunc(X);
<font color="blue"><b>var</b></font> Y;
<font color="blue"><b>begin</b></font>
  Y := Random(100);
  result := X + Y + Y;
<font color="blue"><b>end</b></font>;
</pre>
</blockquote>

is equivalent to


<blockquote>
<pre>
<font color="blue"><b>function</b></font> MyFunc(X: Variant): Variant;
<font color="blue"><b>var</b></font> Y: Variant;
<font color="blue"><b>begin</b></font>
  Y := Random(100);
  result := X + Y + Y;
<font color="blue"><b>end</b></font>;
</pre>
</blockquote>

</li>

<li>
You can join declaration of a variable with its initialization. Local variables are available for
initialization too:


<blockquote>
<pre>
<font color="blue"><b>procedure</b></font> MyProc;
<font color="blue"><b>var</b></font> 
  X: Integer = Random(100);
  Y = 54.3;
<font color="blue"><b>begin</b></font>
..................
<font color="blue"><b>end</b></font>;
</pre>
</blockquote>

</li>

</ul>


<a name="Class Types">
<h4>
Class Types
</h4>

<ul>


<li>
paxPascal supports shared(static) fields of classes. The definition of a static member must begin with the 
reserved word class. For example,

<blockquote>
<pre>
<font color="blue"><b>type</b></font> 
  TFoo = <font color="blue"><b>class</b></font> (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>class</b></font> <font color="blue"><b>procedure</b></font> P();
  <font color="blue"><b>end</b></font>;
</pre>
</blockquote>

</li>

<li>
You can initialize fields of classes:

<blockquote>
<pre>
<font color="blue"><b>type</b></font> 
  TMyClass = <font color="blue"><b>class</b></font>(TObject)
    X: Integer = 100;
    S: <font color="blue"><b>String</b></font> = 'abc'; 
    <font color="blue"><b>constructor</b></font> Create; 
........................
   <font color="blue"><b>end</b></font>;
</pre>
</blockquote>

</li>

<li>
You can define a method's body directly in the class declaration:
</li>

<blockquote>
<pre>
<font color="blue"><b>type</b></font>
  TMyForm = <font color="blue"><b>class</b></font>(TForm)
     <font color="blue"><b>constructor</b></font> Create(Owner: TComponent);
     <font color="blue"><b>begin</b></font>
       <font color="blue"><b>inherited</b></font>;
       Top := 100;
       Left := 200;
       Caption := 'MyForm';
     <font color="blue"><b>end</b></font>;
  <font color="blue"><b>end</b></font>;
</pre>
</blockquote>

<i>Note, that you cannot use nested routines in such case. If you want to use the nested routines
inside of the method body, you must define such method outside of the class declaration.</i>

</ul>

<a name="Record Types">
<h4>
Record Types
</h4>

<ul>

<li>
You can use methods and properties of records:

<blockquote>
<pre>
<font color="blue"><b>type</b></font>
  TPoint = <font color="blue"><b>record</b></font>
  <font color="blue"><b>private</b></font>
    <font color="blue"><b>function</b></font> GetNorm: Integer;
    <font color="blue"><b>begin</b></font>
      result := X*X + Y*Y;
    <font color="blue"><b>end</b></font>;
  <font color="blue"><b>public</b></font>
    X, Y: Integer;
    <font color="blue"><b>property</b></font> Norm: Integer read GetNorm; 
  <font color="blue"><b>end</b></font>;
</pre>
</blockquote>

<i>Note, that you cannot use nested routines in such case. If you want to use the nested routines
inside of the method body, you must define such method outside of the record declaration.</i>
<p></p>



</li>


<li>
You can initialize fields of records:

<blockquote>
<pre>
<font color="blue"><b>type</b></font>
  TRandomPoint = <font color="blue"><b>record</b></font>
    X: Integer = Random(100); 
    Y: Integer = Random(100); 
  <font color="blue"><b>end</b></font>;
</pre>
</blockquote>
</li>

<li>


Method Initialize gives you one more way to initialize the record fields:

<blockquote>
<pre>
<font color="blue"><b>type</b></font>
  TRandomPoint = <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>;
</pre>
</blockquote>
</li>

<li>
You can inherit the record types:

<blockquote>
<pre>
<font color="blue"><b>type</b></font>
  TRandomCircle = <font color="blue"><b>record</b></font> (TRandomPoint)
    R: Integer = Random(100);
  <font color="blue"><b>end</b></font>;
</pre>
</blockquote>

</li>


</ul>


<a name="Array Types">
<h4>
Array Types
</h4>


<ul>
<li>
paxPascal supports 2 kinds of arrays:

<ol>
<li>
Native arrays:

<blockquote>
<pre>
<font color="blue"><b>var</b></font> A[10, 2];
</pre>
</blockquote>

The native array is multi-dimensional zero-based array with elements of Variant type.
<p></p>

</li>

<li>
Object Pascal arrays:

<blockquote>
<pre>

⌨️ 快捷键说明

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