zoukankan      html  css  js  c++  java
  • 使用kbmmw 的调度事件动态显示时间

    kbmmw 里面提供了强大的事件调度功能,今天简单演示一个使用调度事件在窗体上显示时间。

    建立一个新工程。

    放上几个控件

    在窗体里面引用单元 kbmMWScheduler,

    然后添加过程

    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;

    运行程序

     非常简单。

  • 相关阅读:
    常用控件(1)—RadioGroup、CheckBox、Toast
    调用系统剪切板并传输到OtherActivity
    Linux 文件类型
    Handler应用3 — 与Activity不同一线程
    linux下tftp(解决Loading问题 transfer timed out)
    c/c++ 中const的作用
    C++ 初步知识
    类外定义成员函数实例
    ubuntu上Samba服务器配置
    Android全面开发——问题汇总
  • 原文地址:https://www.cnblogs.com/xalion/p/11069795.html
Copyright © 2011-2022 走看看