使用kbmmw 的調度事件動態顯示時間

kbmmw 裏面提供了強大的事件調度功能,今天簡單演示一個使用調度事件在窗體上顯示時間。api

創建一個新工程。spa

放上幾個控件code

 

在窗體裏面引用單元 kbmMWScheduler,orm

而後添加過程blog

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, kbmMWScheduler,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

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

     procedure updatetime(const AScheduledEvent:IkbmMWScheduledEvent);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
   if  not Scheduler.Events.GetByName('showtime').Active then
     Scheduler.Events.GetByName('showtime').Active:=True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
   Scheduler.Events.GetByName('showtime').Active:=false;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Scheduler.Schedule(updatetime).NamedAs('showtime').Synchronized.EveryMSecond(1).Relaxed.DelayInitial(2).Active :=true;

end;

procedure TForm1.updatetime(
  const AScheduledEvent: IkbmMWScheduledEvent);
begin
  label1.Caption:=formatdatetime('yyyy-mm-dd hh:nn:ss ',now);
end;

運行程序事件

 

 很是簡單。it

相關文章
相關標籤/搜索