post your requests, ideas, suggestions..  let's talk!




Creating a simple clock with date
So here it is:

1) create a new form and add 2 'Labels' and a 'Timer' to it; everything else is done from the code itself, as you can see bellow

2) The Form 'OnCreate' event, were we have our defaults, looks like this:

procedure TForm1.FormCreate(Sender: TObject);
begin
Label1.Caption := TimeToStr(Time);
Label2.Caption := DateToStr(Date);
Label1.Left := 2;
Label2.Left := 2 + Label1.Width + 12;
Label1.Top := 0; Label2.Top := 0;
ClientWidth := 2 + Label1.Width +12 + Label2.Width +2;
ClientHeight := Label1.Height;

Label1.Font.Color := clYellow;
Label2.Font.Color := clYellow;
Label1.Font.Name := 'Arial';
Label2.Font.Name := 'Arial';

Form1.Color := clNavy;
Form1.BorderStyle := bsNone;
end;

3) The Form 'OnDblClick' event, were we close our program, looks like this:

procedure TForm1.FormDblClick(Sender: TObject);
begin
Close;
end;

4) The Timer 'OnTimer' event, were we do everything, looks like this:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
{this is were everything is done, using the 'timer'!}
Label1.Caption := TimeToStr(Time);
Label2.Caption := DateToStr(Date);
end;

5) And, to move our form around the screen with the mouse - as we have no caption, there is a simple - although quite old - way, using the Form's 'OnMouseDown', 'OnMouseMove' and 'OnMouseUp' events, as follows:

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
kkeyMove := 1 ;
oldX := X ;
oldY := Y ;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
If kkeyMove = 1 then begin
Form1.Top := Form1.Top - oldY + Y ;
Form1.Left := Form1.Left - oldX + X ;
end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
kkeyMove := 0 ;
end;

6) For the above routines to work, you must - of course - define 3 global variables like this (I am sure you know were..)

{variables to move window with mouse...}
kkeyMove : Integer;
oldX : Integer ;
oldY : Integer ;


And that's it, really! Just run it and see for yourself..

From this, you can evolve the code and create a more complex application like the one you can find at our freeware page. But that's another story, for a future article! wink
24 Jul 2005 by Jose Falcao
0 comments



name:
mail:
(optional)

smile:

smile wink wassat tongue laughing sad angry crying 

| Forget Me

Please note that comments will not be posted immediately
as, due to spam, all posts must be approved by me first...









  [Valid HTML 4.01] [Valid RSS]









powered by CuteNews and