Wednesday, January 5, 2011

Showing The Time Dynamically (Clock)

unit Unit1;

interface

uses
  Windows, SysUtils, Classes, Forms, StdCtrls, ExtCtrls, Controls ;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    Label1: TLabel;
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  Label1.Caption := TimeToStr(Now);
end;

end.

To show the current system time dynamically (that is, a clock), use a Timer and a Label.  The Label Caption should be set empty, initially; and set dimensions manually, with Autosize off.  Set the Timer's Interval to 1000 milliseconds, so it will increment once per second.  Each time the OnTimer event reaches its Interval, it will get the current time with the native Now function, and then rewrite the Label Caption with the current time.

Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Kang Iwan K-sev | Thank's for your visit To My Site - Ridwan Mulyana | Cibeureum