程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 可以計算到的控件

可以計算到的控件

編輯:Delphi

unit mwFastTime;

interface

uses
  SysUtils, Windows, Classes;

type
  TmwFastTime = class(TComponent)
  private
    c, n1, n2: TLargeInteger;
    function GetElapsedTime: ShortString;
    function GetElapsed: Extended;
  protected
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    Property Elapsed: Extended read GetElapsed;
    Property ElapsedTime: ShortString read GetElapsedTime;
    Procedure Start;
    Procedure Stop;
  published
    Property Name;
    Property Tag;
  end;

procedure Register;


implementation

{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

procedure Register;
begin
  RegisterComponents(mw, [TmwFastTime]);
end;


{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

constructor TmwFastTime.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  QueryPerformanceFrequency(c);
end;


{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

destructor TmwFastTime.Destroy;
begin
  inherited Destroy;
end;


{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

function TmwFastTime.GetElapsed: Extended;
begin
{$IFDEF VER120}
  Result:= (_LARGE_INTEGER(n2).QuadPart - _LARGE_INTEGER(n1).QuadPart) / _LARGE_INTEGER(c).QuadPart;
{$ELSE}
  Result:= (n2.QuadPart - n1.QuadPart) / c.QuadPart;
{$ENDIF}
end;

{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

function TmwFastTime.GetElapsedTime: ShortString;
begin
{$IFDEF VER120}
  Result := format(Seconds: %g, [GetElapsed]);
{$ELSE}
  Result := format(Seconds: %g, [GetElapsed]);
{$ENDIF}
end;

{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

Procedure TmwFastTime.Start;
begin
  QueryPerformanceCounter(n1);
end;


{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}

Procedure TmwFastTime.Stop;
begin
  QueryPerformanceCounter(n2);
end;

end.

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved