最好是先学一下语法和如何操作DELPHI。 以下是代码 unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; function sort(const A,B,C:Integer):string; //排序的函数 procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.sort(const A, B, C: Integer): string; //函数的代码 begin if A>B then begin if B>C then Result := inttostr(C)+','+inttostr(B)+','+inttostr(A) else if A > C then result:= inttostr(B)+','+inttostr(C)+','+inttostr(A) else result := inttostr(B)+','+inttostr(A)+','+inttostr(C); end else begin if A > C then result := inttostr(C)+','+inttostr(A)+','+inttostr(B) else if B > C then result := inttostr(A)+','+inttostr(C)+','+inttostr(B) else result := inttostr(A)+','+inttostr(B)+','+inttostr(C) end;end;procedure TForm1.Button1Click(Sender: TObject); begin Edit1.Text:=sort(5,8,7); //调用函数 end;end.
以下是代码
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
function sort(const A,B,C:Integer):string; //排序的函数
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}{ TForm1 }function TForm1.sort(const A, B, C: Integer): string; //函数的代码
begin
if A>B then
begin
if B>C then
Result := inttostr(C)+','+inttostr(B)+','+inttostr(A)
else
if A > C then
result:= inttostr(B)+','+inttostr(C)+','+inttostr(A)
else
result := inttostr(B)+','+inttostr(A)+','+inttostr(C);
end
else
begin
if A > C then
result := inttostr(C)+','+inttostr(A)+','+inttostr(B)
else if B > C then
result := inttostr(A)+','+inttostr(C)+','+inttostr(B)
else
result := inttostr(A)+','+inttostr(B)+','+inttostr(C)
end;end;procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Text:=sort(5,8,7); //调用函数
end;end.