Delphi_03_Delphi_Object_Pascal_기본 구문01

18555 단어
이번에는 기본 문법의 첫 번째 부분으로 변수, 변수 초기화, 상수, 연산자, 문자열 등의 내용을 포함한다.
{
              Delphi Pascal      
1、         
2、  
3、   
3、
4、

}
program Syntax;

{$APPTYPE CONSOLE}

uses
  SysUtils,Windows,StrUtils;


{         
1、Delphi               
2、Delphi       var      
3、     :
                var           :      ;
                       
4、      
                var           :      =     ;

5、                      
}
var
    //          
    greetWord:string;
    //          
    nAdd,nAddFactor:integer;

    //      
    rad : single = 5.0 ;

    //      
    chinaName:WideString;
    //ansichar         
    englishName:AnsiString;

    //             
    noInitString:string;

    //     win32      
    dirWideString:widestring;
    dirString:ansistring;



{         
1、Delphi          
        true   Boolean    true
        false  Boolean    false

2、 Delphi    const        
3、     
                const         :         =     。
4、       ,           ,Delphi           
           ,           。           ,  
                             。
      :
            10      shortint  
5、           ,   C         ,  
    10        
    2.06      
    'Hello world'      
    'a'     

}
const
    pi:single=3.1415926;

{         
1、Delphi                           。
2、         :
        Sizeof()
        Ord()
        Chr()
        Trunc()
        Round()
        High()
        Low()
           ,       ,
}

begin
    //      :=
    greetWord := 'Hello, Wellcome to Delphi world!';

    //      =       
    nAdd := 10;
    nAddFactor := 1;
    if nAdd = nAddFactor then
    begin
        writeln('Equal.');
    end;

    //       <>       ,         TRUE
    if nAdd <> nAddFactor then
    begin
        writeln('Not Equal.');
    end;

    //       and   ,  Delphi                  
    if (1 = nAdd) and (2 <> nAddFactor )then
    begin
        writeln('The judge is ture.');
    end;

    //      or    ,   Delphi                  
    if (1 = nAdd) or (2 <> nAddFactor )then
    begin
        writeln('The judge is ture.');
    end;


    //     not  ,   Delphi                  
    if not (1 = nAdd) then
    begin
        writeln('1 is not equal nAdd.');
    end;

    {            
    1、        C    ,              
    2、mod       
    3、div      ,         
    4、/         ,         
    }
    writeln('     3 div 2     :');
    writeln(3 div 2);

    writeln('      3 / 2     :');
    writeln(3 / 2);

    writeln('    3 mod 2     :');
    writeln(3 mod 2);


    {            
    1、Delphi            
    2、and     
    3、or      
    4、not     
    5、xor      
    6、shl      
    7、shr      
    }
    writeln('2 and 5        :');
    writeln(2 and 5);

    writeln('2 or 5        :');
    writeln(2 or 5);

    writeln('not 2        :');
    writeln(not 2);

    writeln('2 xor 5         :');
    writeln(2 xor 5);

    writeln('2 shl 5         :');
    writeln(2 shl 5);

    writeln('2 shr 5         :');
    writeln(2 shr 5);

    {            
    1、inc   
    2、dec   
    3、        inc(a);        a := a + 1
                    inc(a, b);        a := a + b
    }
    writeln('nAdd is:');
    writeln(nAdd);
    writeln('Inc(nAdd) is:');
    Inc(nAdd);
    writeln(nAdd);
    Dec(nAdd);
    writeln('Dec(nAdd) is:');
    writeln(nAdd);

    {           
    1、   8 、16 、32         ,64      
    2、4 、6 、8 、10    ,64     
    3、1    、2    
    4、     、     
    5、NULL     、NULL      
    6、        
    7、1  、2  、4  boolean  
    }

    //ansichar          
    if sizeof(char)=sizeof(ansichar) then
    begin
        writeln('char and ansichar have the same size.');
    end;

    //char    widechar         
    if sizeof(char)=sizeof(widechar) then
    begin
        writeln('char and widechar have the same size.');
    end;

    {          
    1、shortstring    256        ,ansichar   
    2、ansistring         ansichar       
    3、widestring         widechar       
    4、pchar   NULL         ,  C   char*
    5、pansichar  NULL   ansichar     
    6、pwidechar  NULL    widechar      
    7、      string      ansichar   
    }

    (*
    1、       {$H+}   {$H-}      string     
       {$H+}     string   ansichar
       {$H-}     string   shortchar
    2*)
    writeln(sizeof(shortstring));

    //         
    chinaName := '  ';

    //         
    englishName := 'England';

    writeln(chinaName);
    writeln(englishName);

    {       ansistring   
    1、string           
    2、        string       
    3、  SetLength()        
    4、           
    5、string            ,        ,       
            string   
    6、        +     
    }
    //         
    //noInitString[0] := 'a';
    //               ,   SetLength()         。
    SetLength(noInitString,1);
    noInitString := 'a' ;

    //    +         ,            
    noInitString := noInitString + ' apple';
    writeln(noInitString);

    {       ansistring  Win32        
    1、   ansistring    NULL       ,     Win32     
    }
    SetLength(dirString,256);
    //SysAllocStringLen(dirWideString,256);
    //  windows  
    //GetWindowsDirectory(PWideChar(dirWideString),256);
    dirString := dirWideString;
    writeln(dirString);

    readln;
end.

 
전재를 환영합니다. 전재는 출처를 밝혀 주십시오.

좋은 웹페이지 즐겨찾기