資源描述:
《objectpascal編程基礎(chǔ)》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、第3章ObjectPascal編程基礎(chǔ)程序結(jié)構(gòu)(項(xiàng)目文件,單元文件)變量說(shuō)明(var)控制結(jié)構(gòu)21學(xué)習(xí)教程教材多媒體課件【友情分享】GOODGOODSTUDAY,DAYDAYUP↗↗項(xiàng)目文件-主程序programProject1;usesForms,Unit1in'Unit1.pas'{Form1};{$R*.res}beginApplication.Initialize;Application.CreateForm(TForm1,Form1);Application.Run;end.單元文件單元文件uni
2、tUnit1;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls;typeTForm1=class(TForm)Label1:TLabel;Edit1:TEdit;Label2:TLabel;Edit2:TEdit;Edit3:TEdit;單元文件Button1:TButton;Button2:TButton;procedureButton1Click(Sender:
3、TObject);procedureButton2Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}end;varForm1:TForm1;implementation{$R*.dfm}單元文件procedureTForm1.Button1Click(Sender:TObject);varsno,sname:string;beginsno:=edit1.Text;sname:=edit2.Text;edit
4、3.Text:='welcometodelphi:'+sno+sname;end;procedureTForm1.Button2Click(Sender:TObject);beginForm1.Close;end;end.變量說(shuō)明procedureTForm1.Button1Click(Sender:TObject);vareno,ename:String;//字符串型(隱含最大長(zhǎng)度256個(gè)字符)age:Integer;//整型sal:Real;//實(shí)型married:Boolean;//布爾型ch:Cha
5、r;//字符型,變量只存放一個(gè)字符cnt:word;//無(wú)符號(hào)16位整型begin……end;運(yùn)算符ObjectPascal常用的運(yùn)算符:算術(shù)運(yùn)算符:+、-、*、/、div(整除)、mod(求余)布爾運(yùn)算符:and(與)、or(或)、not(非)字符串運(yùn)算符:+(字符串拼接)集合運(yùn)算符:+(并)、-(差)、*(交)、in(屬于)關(guān)系運(yùn)算符:=、<>(不等于)、>、<、<=、>=控制語(yǔ)句-分支語(yǔ)句If條件then語(yǔ)句1else語(yǔ)句2;在第一個(gè)編輯框中輸入星期幾,然后按OK按鈕,如果輸入的是saturday或s
6、unday,則在第2個(gè)編輯框中顯示一條信息,并把窗體變黃。控制語(yǔ)句-分支語(yǔ)句procedureTForm1.Button1Click(Sender:TObject);beginif(Edit1.text='saturday')or(Edit1.text='sunday')thenbeginedit2.text:='Whyareyouworkingtoday!';//顯示一條信息Form1.Color:=clYellow;//將窗體顏色置為黃色endelsebeginedit2.text:='workday'
7、;Form1.Color:=clBtnFace;//將窗體顏色置為隱含顏色end;end;條件語(yǔ)句嵌套例條件語(yǔ)句嵌套procedureTForm1.Button1Click(Sender:TObject);vargrade:integer;begingrade:=strtoint(edit1.Text);//將輸入的分?jǐn)?shù)賦值給變量gradeif(grade>=85)and(grade<=100)thenedit2.Text:='優(yōu)秀'elseif(grade>=60)and(grade<85)then//語(yǔ)
8、句嵌套edit2.Text:='通過(guò)'elseif(grade>=0)and(grade<60)then//再次嵌套edit2.Text:='不通過(guò)'elseedit2.Text:='成績(jī)有誤';end;設(shè)置多分支if(grade>=85)and(grade<=100)thenedit2.Text:='優(yōu)秀'//分支1elseif(grade>=60)and(grade<85)thenedit2.Text:='通