首页 > 数据库技术 > 详细

Handbook之012:函数类别构型

时间:2015-10-25 06:06:05      阅读:316      评论:0      收藏:0      [点我收藏+]

定义函数构型,然后在再调用函数

技术分享

代码如下:

unit Unit1;

interface

uses
  Winapi.Windows,
  Winapi.Messages,
  System.SysUtils,
  System.Variants,
  System.Classes,
  Vcl.Graphics,
  Vcl.Controls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  System.Diagnostics,
  System.Math;

//函数定义
procedure ShowOnMemo(ACount: Integer);
var
  m_Watch: TStopwatch;
  I, J: Integer;
begin
  J := 0;
  m_Watch := TStopwatch.StartNew;
  for I := 0 to ACount do
  begin
    J := Max(I, J);
  end;
  m_Watch.Stop;
  Form1.Memo1.Lines.Add(循环总耗时:  + m_Watch.ElapsedMilliseconds.ToString);
end;
//定义函数构型

type
  TIntProc = procedure(Num: Integer);

//计时
procedure TForm1.Button1Click(Sender: TObject);
var
  m_Pro: TIntProc;
  m_Count: Integer;
begin
  m_Pro := ShowOnMemo;
  m_Count := 2000000;
  m_Pro(m_Count);
end;

end.

Handbook之012:函数类别构型

原文:http://www.cnblogs.com/GodPan/p/4908121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!