zoukankan      html  css  js  c++  java
  • (转)Delphi 语言基础

    【注释】

    // 注释内容      行注释,只能注释单行,从注释符开始一直到行尾都是注释
    { 注释内容 }     一元块注释,可以注释多行,从注释符头到注释符尾之间的都是注释
    (* 注释内容 *)   二元块注释,可以注释多行,从注释符头到注释符尾之间的都是注释

      同一类型的注释不能嵌套,不同类型的注释可以嵌套。例如:

    正确:
    (* // 注释1
       // { 注释2 }
       { 注释3 } *)


    错误:
    { // 注释1
      // { 注释2 }

      { 注释3 } }



    【系统保留字】

    and            array          as             asm
    begin          case           class          const
    constructor    destructor     dispinterface  div
    do             downto         else           end
    except         exports        file           finalization
    finally        for            function       goto
    if             implementation in             inherited
    initialization inline         interface      is
    label          library        mod            nil
    not            object         of             or
    out            packed         procedure      program
    property       raise          record         repeat
    resourcestring set            shl            shr
    string         then           threadvar      to
    try            type           unit           until
    uses           var            while          with
    xor



    【系统关键字】

    absolute       abstract       assembler      automated
    cdecl          contains       default        dispid
    dynamic        export         external       far
    forward        implements     index          message
    name           near           nodefault      on
    overload       override       package        pascal
    private        protected      public         published
    read           readonly       register       reintroduce
    requires       resident       safecall       stdcall
    stored         virtual        write          writeonly



    【变量】

      在 Delphi 中变量在使用前必须声明,声明变量时必须指定一种数据类型。例如:

    var
      iNum: Integer;

      当你声明全局变量时,你可以赋给它一个初值。例如:

    var
      iNum: Integer = 10;



    【常量】

      对于在程序运行期间保持不变的值,Pascal 允许通过常量来声明。声明常量不必指定数据类型,但需要赋一个初始值。编译器会根据所赋的初始值自动选用合适的数据类型。如果你想告诉 Delphi 采用特定的类型,也可在声明中加入类型名,例如:

    const
      conNum  = 1000;
      conNum: Integer = 1000;



    【资源字符串】

      还可以通过 resourcestring 关键字来声明资源字符串。资源字符串也是一种常量,只不过资源字符串是存储在EXE程序的资源部分,而不是代码部分。采用资源的好处一方面可让 Windows 来完成有效的内存处理,另一方面不用更改源代码就可实现程序的本地化 (把字符串翻译成不同的语言)。

    resourcestring
      rsMenuName_File = '文件(&F)';
      rsMenuName_Edit = '编辑(&E)';



    【标识符】

      变量和常量都必须有一个名字(比如上面的 iNum、conNum、rsMenuName_File),以便其它程序代码能够调用它,这些名字统称为标识符,除了变量名和常量名外,还有函数名、单元名、类 名、对象名、属性名、方法名、结构名、接口名、控件名等等所有用户自己定义的名字都叫标识符。定义标识符必须遵循以下规则:

    1、标识符只能右数字、字母(大小写)和下划线( _ )组成。
    2、标识符不能以数字开头。
    3、标识符不能和“系统保留字”或“系统关键字”相同。



    【运算符】

    1、赋值运算符

    :=(赋值)

    ----------

    2、算术运算符

    +(加) -(减) *(乘) /(除)
    div(整除) mod(取余)

    ----------

    3、逻辑运算符

    and(逻辑与) or(逻辑或) not(逻辑非) xor(逻辑异或)
    shl(位左移) shr(位右移)

    ----------

    4、关系运算符

    =(相等) <>(不相等) >(大于) =(大于等于) =(是否超集) =(是否相同) <>(是否不同)
    in(是否为成员)

    ----------

    6、字符串运算符

    +(连接字符串)



    【基本数据类型】

    1、整数类型

    (+-8位)  ShortInt   (+8位)  Byte
    (+-16位) SmallInt   (+16位) Word
    (+-32位) LongInt    (+32位) LongWord
    (+-64位) Int64      (+64位) UInt64
    (+-16/32)Integer    (+16/32)Cardinal

    ----------

    2、实数类型

    (+-32位)  Single    (精度7-8)
    (+-64位)  Double    (精度15-16)
    (+-80位)  Extended  (精度19-20)

    (+-64位)  Real      (精度15-16)
    (+-48位)  Real48    (精度11-12)
    (+-64位)  Comp      (精度19-20)
    (+-64位)  Currency  (精度19-20)

    ----------

    3、布尔类型

    (+-8位)   ByteBool
    (+-16位)  WordBool
    (+-32位)  LongBool
    (+-8位)   Boolean

    ----------

    4、字符类型

    (+8位)    AnsiChar
    (+16位)   WideChar

    Char = WideChar

    ----------

    5、字符串类型

    (2B-256B) ShortString
    (4B-2GB)  AnsiString
    (4B-2GB)  WideString

    String = WideString

    ----------

    6、日期类型

    (+64位)   TDateTime

    TDate = TDateTime
    TTime = TDateTime

    ----------

    7、枚举类型

    (wsNormal, wsMinimized, wsMaximized)
    (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
    (Monday=1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)
    (Monday=1, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday=0)

    ----------

    8、子界类型

    1..100
    'A'..'Z'
    Monday..Sunday

    ----------

    9、数组类型

    Array [0..9] of Integer; { 一维整数数组 }
    Array [1..10, 1..100, 1..5] of Char;{ 多维字符数组 }
    Array [0..9] of TButton; { 一维控件数组 }
    Array of Byte; { 动态字节数组 }

    type
      ByteArray = Array of Byte; { 定义动态字节数组类型 }
      StringArray = Array of Sting; { 定义动态字符串数组类型 }
      ButtonArray = Button of TButton;{ 定义动态控件数组类型 }

    ----------

    10、集合类型(最多 256 个元素)

    Set of 1..100
    Set of Byte
    Set of (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday)

    ----------

    11、指针类型

    Pointer;
    PPointer = ^Pointer;

    PInteger PWord PString PChar PCardinal ...

    ----------

    12、文件类型

    File;
    File of Integer;
    File of Array [0..9999] of Integer;
    File of TButton;

    ----------

    13、变体类型

    Variant

    ----------

    14、过程与函数类型

    Procedure
    Function

    ----------

    15、记录类型

    Record

    ----------

    16、类类型

    Class

    ----------

    17、接口类型

    Interface

    ----------

    18、特定的Windows 类型

    HANDLE, DWORD, UNIT ...



    【语句】

    if 条件 then
      ...

    if 条件 then
      ...
    else
      ....

    if 条件 then
      ...
    else if 条件 then
      ...
    else if 条件 then
      ...

    if 条件 then
    begin
      ...
    end
    else if 条件 then
    begin
      ...
    end
    else
    begin
      ...
    end;

    ----------

    case 有序类型 of
      1:
        ...
      2:
        ...
      n:
        ...
    end;

    case 有序类型 of
      1:
        ...
      2:
        ...
      n:
        ...
    else
      ...
    end;

    case 有序类型 of
      1:
        begin ... end;
      2:
        begin ... end;
      n:
        begin ... end;
    else
      begin ... end;
    end;

    ----------

    repeat
      ...
    until 条件

    ----------

    while 条件 do
      ...

    while 条件 do
    begin
      ...
    end;

    ----------

    for I := 1 to 100 do
      ...

    for I := 100 downto 1 do
      ...

    for I := 1 to 100 do
    begin
      ...
    end;

    for Item in Set do
      ...

    for Item in Set do
    begin
      ...
    end;

    ----------

    break;     { 退出整个循环体 for while repeat }
    continue;  { 重新开始下一次循环 for while repeat }
    exit;      { 退出函数或过程 function procedure }

    ----------

    with Button1 do
      ..

    with Buttn1, Button2 do
    begin
      ...
    end;

    ----------

    goto 语句(不建议使用)

    function Test(): Integer;
    label AA; // 声明标签
    var
      I: Integer;
    begin
      I := 0;
    AA: // 使用标签
      I := I + 1;
      if I < 10 then
        goto AA; // 转到标签
      Result := I;
    end;


    版权说明:作者:张颖希PocketZ's Blog
    出处:http://www.cnblogs.com/PocketZ
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
    若本文为翻译内容,目的为练习英文水平,如有雷同,纯属意外!有不妥之处,欢迎拍砖

  • 相关阅读:
    VMware虚拟机安装红帽系统无法上网解决办法(转)
    二维指针的malloc内存分配(转)
    c语言中如何通过二级指针来操作二维数组
    如何把一个二维数组的地址赋给一个二维指针?
    二维数组及二维指针的传递及一些思考(转)
    js怎么让时间函数的秒数在页面上显示是变化的
    jquery 实现各种统计图网址
    WEB的相关知识总结
    JS同名方法,
    web components思想如何应用于实际项目
  • 原文地址:https://www.cnblogs.com/PocketZ/p/2983575.html
Copyright © 2011-2022 走看看