资源描述:
《DELPHI语言基础知识教材.ppt》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、DELPHI语言基础DELPHI语言基础DELPHI语言基础常量无需定义1、整型常量2、实数常量3、布尔常量4、字符常量5、字符串常量字面常量DELPHI语言基础常量符号常量需定义语法规则:const<常量标识符>=<常量或常量表达式>注:没有“:”号。例:constpi=3.14;//正确pi1=abc//错误pi2=-pi;//正确pi=-k//错误(即使k被定义为变量)DELPHI语言基础unitUnit1;interfaceusesWindows,Messages,SysUtils,Variants,C
2、lasses,Graphics,Controls,;typeTForm1=class(TForm)Button1:TButton;procedureButton1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;constpi=3.14;implementation{$R*.dfm}procedureTForm1.Button1Click(Sender:TObject);
3、constpi=3.1415;beginend;end.DELPHI语言基础变量语法规则:var<变量标识符>:<变量类型>例:varX:integer;Y,z:string;注:不区分大小写unitUnit1;interfaceusesSysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;procedureButton1Click(Sender:TObj
4、ect);private{Privatedeclarations}public{Publicdeclarations}i:integer;end;varForm1:TForm1;i:integer;x,y:string;implementation{$R*.dfm}procedureTForm1.Button1Click(Sender:TObject);vari:integer;st:string;beginend;end.DELPHI语言基础类型常量语法规则:const<常量标识符>:<数据类型>=<常量或常
5、量表达式>注:没有“:”号。例:constpi:integer=3.14;//正确pi1:string=abc//错误符号常量和类型常量唯一不同:类型常量指定了类型。DELPHI语言基础unitUnit1;interfaceusesSysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;procedureButton1Click(Sender:TObject
6、);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;constpi:integer=3;pi1:string=‘abc’;implementation{$R*.dfm}procedureTForm1.Button1Click(Sender:TObject);constpi:integer=3.14;pi1:string=abcbeginend;end.DELPHI语言基础DELPHI语言基础自定义类型语法规则:t
7、ype<标识符>=<数据类型表达式>注:没有“:”号。例:typeint=integer;//int代替integer类型str=array[1..10]ofstring;//str代替string数组DELPHI语言基础unitUnit1;interfaceusesSysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Button1:TButton;procedureButton1Cl
8、ick(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;Typeint=integer;str=array[1..10]ofstring;varForm1:TForm1;implementation{$R*.dfm}procedureTForm1.Button1Click(Sender: