谁帮我看下这个过程的使用有何不妥,从小到大排列三个数
unit Unit1;interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure pailie(a,b,c:Integer); //声明一个过程,有3个整数
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.pailie(a,b,c:Integer); //定义过程,按照从小到大的顺序排列
var
n:Integer;
begin
a:=StrToInt(Edit1.Text);
b:=StrToInt(Edit2.Text);
c:=StrToInt(Edit3.Text);
if a<b then
begin
n:=b;
b:=a;
a:=n;
end;
if a<c then
begin
n:=c;
c:=a;
a:=n;
end;
if b<c then
begin
n:=c;
c:=b;
b:=n;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);//使用过程
var
x,y,z:Integer;
begin
pailie(x,y,z); //将过程的a,b,c 三个整数按照从大到小的顺序传给x,y,z
Label1.Caption:=IntToStr(x) + ',' + IntToStr(y) +',' + IntToStr(z);//显示出来
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Button1.Caption:='顺序排列';
Label1.Caption:='';
end;
end.
页:
[1]