functimeru.pas

来自「delphi win32api编程」· PAS 代码 · 共 62 行

PAS
62
字号
unit FuncTimerU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
  Loop1, Loop2: Integer;        // general loop control counters
  StartCount,                   // this holds the start and stop time for
  EndCount: TLargeInteger;      // the function
  Frequency: TLargeInteger;     // the frequency of the high resolution timer
  ElapsedTime: Extended;        // holds the total elapsed time
begin
  {retrieve the frequency of the high resolution timer}
  QueryPerformanceFrequency(Frequency);

  {begin timing the function by retrieving the current
   value of the high resolution timer}
  QueryPerformanceCounter(StartCount);

  {perform some function. in this example, we fill a 100 X 100
   cell string grid with numbers.}
  for Loop1 := 0 to 99 do
    for Loop2 :=0 to 99 do
      StringGrid1.Cells[Loop2, Loop1] := IntToStr((Loop1*100)+Loop2);

  {the function is complete. retrieve the current value
   of the high resolution counter as our end count}
  QueryPerformanceCounter(EndCount);

  {this formula computes the total amount of time the function
   took to complete}
  ElapsedTime := (EndCount - StartCount)/Frequency;

  {display the elapsed time, in seconds}
  Label1.Caption := 'Elapsed Time: '+FloatToStr(ElapsedTime)+' seconds.';
end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?