当前位置:首页>开发>正文

delphi编程 Delphi函数简介

2023-05-03 19:31:29 互联网 未知 开发

 delphi编程 Delphi函数简介

delphi编程

unit Unit1 interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls type TForm1 = class(TForm) maxnum: TButton minnum: TButton avenum: TButton Label1: TLabel procedure maxnumClick(Sender: TObject) procedure FormActivate(Sender: TObject) procedure minnumClick(Sender: TObject) procedure avenumClick(Sender: TObject) private { Private declarations } public { Public declarations } end var Form1: TForm1 a:array[1..10] of integer implementation {$R *.dfm} procedure TForm1.maxnumClick(Sender: TObject) var i,max:integer begin max:=a[1] for i:=2 to 10 do if a[i]>max then max:=a[i] label1.Caption :=inttostr(max) end procedure TForm1.FormActivate(Sender: TObject) var i:integer begin for i:=1 to 10 do begin randomize a[i]:=random(100) label1.Caption :=label1.Caption inttostr(a[i]) end end procedure TForm1.minnumClick(Sender: TObject) var i,min:integer begin min:=a[1] for i:=2 to 10 do if a[i]

Delphi函数简介

跳转语句ObjectPascal的跳转语句有if和case两个。if语句if语句会计算一个表达式,并根据计算结果决定程序流程。在上文的例程中,根据ColorDialog.Execute的返回值,决定窗体的背景颜色。if保留字后跟随一个生成Boolean值True或False的表达式。一般用“=”作为关系运算符,比较产生一个布尔型值。当表达式为True时,执行then后的语句。否则执行else后的代码,if语句也可以不含else部分,表达式为False时自动跳到下一行程序。if语句可以嵌套,当使用复合语句表达时,复合语句前后需加上begin…end。else保留字前不能加“;”,而且,编译器会将else语句视为属于最靠近的if语句。必要时,须使用begin…end保留字来强迫else部分属于某一级的if语句。

最新文章