Delphi : การตั้งเวลาให้โปรแกรมทำงานในชั่วโมงที่กำหนด

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, JvComponentBase, JvThreadTimer, StdCtrls;

type
  TForm1 = class(TForm)
    btnClose: TButton;
    ttTimer: TJvThreadTimer;
    procedure ttTimerTimer(Sender: TObject);
    procedure btnCloseClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

const
   FOCUS_TIME : array[0..1] of word = (6, 18);

procedure TForm1.ttTimerTimer(Sender: TObject);
var
  i: byte;
  H,M,S,Ms: word;
begin
  Form1.caption:= formatdatetime('hh:mm:ss', now);

  ttTimer.Enabled := false;
  try
    DecodeTime(Now, H,M,S,Ms);
    for i := 0 to high(FOCUS_TIME) do
    begin
      if H = FOCUS_TIME[i] then
      begin
         Showmessage('process somting...');
      end;
    end;
  finally
    ttTimer.Enabled := true;
  end;
end;

procedure TForm1.btnCloseClick(Sender: TObject);
begin
  Self.close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ttTimer.Enabled := true;
end;

end.

Comments