开发学院软件开发Delphi 可以计算到<<毫秒级>>的控件 阅读

可以计算到<<毫秒级>>的控件

 2006-02-04 13:30:51 来源:WEB开发网 闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹闂傚倷绀侀幉锟犲垂閻㈠灚宕查柟鎵閸庡秵銇勯幒鎴濃偓鐢稿磻閹炬枼妲堟繛鍡楃С濞岊亞绱撻崒姘扁枌闁瑰嚖鎷�婵犵數濮幏鍐川椤撴繄鎹曢梻渚€娼уú銈吤洪妸鈺佺劦妞ゆ帊鑳堕埊鏇㈡煏閸モ晛浠х紒杈╁仱閺佹捇鏁撻敓锟�闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹  闂傚倷鑳舵灙缂佺粯顨呴埢宥夊即閵忕姵鐎梺缁樺姈椤愮厧鈽夊Ο閿嬬€婚梺褰掑亰閸撴稑鈻斿鑸碘拺闁告稑饪村▓鏃€绻涚仦鍌氬闁崇粯鎹囬獮瀣攽閹邦剚顔傛俊鐐€栧濠氬储瑜忛幉鎾晸閿燂拷
核心提示:unit mwFastTime;interfaceuses SysUtils, Windows, Classes;type TmwFastTime = class(TComponent) PRivate c, n1, n2: TLargeInteger; function GetElapsedTime: Sh

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.

Tags:可以 计算 lt

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接