zoukankan      html  css  js  c++  java
  • delphi 学习笔记

    只是简单的c和delphi对照,这样学的很快,笔记记得很随性,只是为了看点小代码,有帮助就看看吧,delphi 已经差不多没落了。

     

    1.object pascal 语法

     

    一.首先是main函数

    Program first;  {program name}

    var a:integer;  {varent declare}

    begin           {program sub}

        Writeln('this is nextline write');

        write('this will not change line');

        Readln;

        Readln(a);

        Readln;   {here can del the ';'}

    end.          {must have '.'}

     

    二.然后是数据类型和变量的声明

    (1) 整型

    int          --->      Integer

    usigned int  --->      Cardinal

    short        --->      Smallint

    char         --->      Shortint

    long         --->      Longint       {this is depend on the compiler}

    int64        --->      Int64

    BYTE         --->      Byte (usigned)

    WORD         --->      Word (usigned)

    DWORD        --->      Longword (usigned)

    8位          --->      Real

     

    (2) 字符

    CHAR         --->      Char

    char         --->      AnsiChar

    wchar        --->      WideChar

     

    (3) 字符串

    char*        --->      PChar

    int* a       --->      var a:^integer

    a = &b       --->      a = @b

    *a           --->      a^

     

    (4) 逻辑

    BOOLEAN      --->      Boolean

                           ByteBool

                           WordBool

                           LongBool

     

    (5) 运算符

    /   --->  div

    !=  --->  <>

    &&  --->  and

    %   --->  mod

     

    (6)结构体

    fuck  ,the type can instead of struct and enum,for example

     

    type color=(red,white,black);

     

    type

        a:Integer;

        name:PChar;

        age:Integer;

    end;

     

    (7)#define

    you know , delphi can use  const NUM=$1 to instead of #define NUM 0x1

    #define LANG_NEUTRAL 0x00  ---> const LANG_NEUTRAL=$00

     

     

    三、条件和循环

    if xx

    then

        xxx

     

     

    if xx

    then

        xxx   {这个地方不要分号}

    else

        xxx;

    上面这两种写法只能适合于单条语句,如果要写几行语句需要这样

    if xx

    then

        begin

            xxx;

            xxx           {在begin和end间,最后一句可以不加;}

        end;

    else

        begin

            xxx;

            xxx

        end;

     

     

    case n of

        1:xxx;

        2,3:yyy;

        4: mmm;   

        6..9: ccc     {同理 这个地方可以不加分号}

    end;

     

     

    while xxx do

    begin

     

    end;

     

    reapet 

    inc(a)

    untill xx>10

     

    for  x:= num1 to num2  do

    begin

     

    end;

     

    四、 常用函数

    int(a) 取a的整数部分

    pi     π的取值

    random  产生0~1的随机数

    random(n) 产生0~n的随机数

    round(n) 求n四舍五入后的整数

    trunc(n) 取小数的整数部分

    inc(a,n)/inc(a)  自增,等价于 a := a+n

    dec....          自减,同上

     

     

    五、输入输出

    Writeln(2:3)   空3格输出2

    Writeln('2=',3) 输出2=3

    Readln   ---> getchar()

  • 相关阅读:
    屏蔽Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键(Windows 98/Me)
    获取本月第一天和最后一天的最简单的写法
    PHP程序员的优化调试技术和技巧
    Windows关机函数ExitWindowsEx使用大全(适用Windows所有操作平台)
    屏蔽Alt+Enter、Ctrl+Alt+Del、Ctrl+Esc等功能键(Windows 98/Me)
    PHP程序员的优化调试技术和技巧
    Ajax,再生还是幻灭好文推荐
    RAID 分类
    Ajax,再生还是幻灭好文推荐
    Windows关机函数ExitWindowsEx使用大全(适用Windows所有操作平台)
  • 原文地址:https://www.cnblogs.com/magicdmer/p/4458361.html
Copyright © 2011-2022 走看看