+ -
当前位置:首页 → 问答吧 → 求助高手

求助高手

时间:2011-12-20

来源:互联网

我是一个菜鸟,想声明一个程序并且调用它,函数实现的功能是比较三个数的大小,但是不知道怎样声明函数并且怎样调用,在哪个位置写程序,请高手帮我把完整的程序,(从开始到结尾)写一下,小弟感激不尽,,,,

作者: xhudqlg   发布时间: 2011-12-20

这个。。。。。。还是先找pascal的语法看一看吧

作者: sz_haitao   发布时间: 2011-12-20

最好是先学一下语法和如何操作DELPHI。
以下是代码

Delphi(Pascal) code

unit Unit1;

interface

uses
  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.


作者: rocket204   发布时间: 2011-12-21

热门下载

更多