Wednesday, October 6, 2010

Timers

In BB.Timer there are a few classes with the unique purpose of dealing with timers:

A timer that does not rely on VCL messages and also has a higher precision.


TTimerEx = class(TComponentEx)
  private
    FEnabled: boolean;
    FOnTimer: TNotifyEvent;
    FInterval: cardinal;
    FThread: TThreadEx;

    procedure SetEnabled(const aValue: boolean);
  protected
    procedure Execute(aSender: TObject);
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property Interval: cardinal read FInterval write FInterval;
    property Enabled: boolean read FEnabled write SetEnabled;
    property OnTimer: TNotifyEvent read FOnTimer write FOnTimer;
  end;
A simple class (I think it should be a record) that helps measuring intervals of times (same behaviour as a crono)
TCrono = class(TComponentEx)
  private
    FFrequency: int64;
    FStart: int64;
    FPaused: boolean;
    FStarted: boolean;
  public
    constructor Create; override;
    function RDTSC: int64;
    procedure Start;
    function Stop: int64;
    procedure Pause;
    procedure Resume;

    property Paused: boolean read FPaused;
    property Started: boolean read FStarted;
  end;
Same as a Timer but is only executed once and then is freed (can be useful for chain events, but if they become more complex you rather use TTask)
TTrigger = class(TThreadEx)
  private
    FTime: cardinal;
    FOnTimer: TNotifyEvent;
  protected
    procedure Execute; override;
  public
    constructor Create; override;

    property Time: cardinal Read FTime Write FTime;
    property OnTimer: TNotifyEvent Read FOnTimer Write FOnTimer;
  end;

No comments:

Post a Comment