Answer to Question #32477 in Delphi | Pascal for peter

Question #32477
using delphi components write a program showing system clock with time zones
1
Expert's answer
2013-06-28T04:53:47-0400
unit unMain;


interface


uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, Buttons, Grids;


type
TForm1 = class(TForm)
Timer1: TTimer;
lbH: TLabel;
lbM: TLabel;
lbS: TLabel;
lb1: TLabel;
Label1: TLabel;
BitBtn1: TBitBtn;
sg: TStringGrid;
Label2: TLabel;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;


implementation


{$R *.DFM}


//accounting transition time in 24 hours
function ttt(Ht, i: integer): integer;
begin
if (Ht + i) >= 24 then Result:= Ht + i - 24
else Result:= Ht + i;
end;


procedure TForm1.Timer1Timer(Sender: TObject);
var
SystemTime: TSystemTime;
H, M, S: word;
i: integer;
begin
// local time
lb1.Caption:= TimeToStr(Time);


GetSystemTime(SystemTime);
H:= SystemTime.wHour;
M:= SystemTime.wMinute;
S:= SystemTime.wSecond;
//lbH.Caption:= IntToStr(H);
//lbM.Caption:= IntToStr(M);
//lbS.Caption:= IntToStr(S);
//H:= 10;
with sg do begin
// 11
//// output time zones to the west of Greenwich
if (H - 11) < 0 then i:= 24 + H -11
else i:= H - 11;
Cells[0,1]:= ' ' + IntToStr(i);
// 10
if (H - 10) < 0 then i:= 24 + H -10
else i:= H - 10;
Cells[1,1]:= ' ' + IntToStr(i);


if (H - 9) < 0 then i:= 24 + H -9
else i:= H - 9;
Cells[2,1]:= ' ' + IntToStr(i);


if (H - 8) < 0 then i:= 24 + H -8
else i:= H - 8;
Cells[3,1]:= ' ' + IntToStr(i);


if (H - 7) < 0 then i:= 24 + H -7
else i:= H - 7;
Cells[4,1]:= ' ' + IntToStr(i);


if (H - 6) < 0 then i:= 24 + H -6
else i:= H - 6;
Cells[5,1]:= ' ' + IntToStr(i);


if (H - 5) < 0 then i:= 24 + H -5
else i:= H - 5;
Cells[6,1]:= ' ' + IntToStr(i);


if (H - 4) < 0 then i:= 24 + H -4
else i:= H - 4;
Cells[7,1]:= ' ' + IntToStr(i);


if (H - 3) < 0 then i:= 24 + H -3
else i:= H - 3;
Cells[8,1]:= ' ' + IntToStr(i);


if (H - 2) < 0 then i:= 24 + H -2
else i:= H - 2;
Cells[9,1]:= ' ' + IntToStr(i);


if (H - 1) < 0 then i:= 24 + H -1
else i:= H - 1;
Cells[10,1]:= ' ' + IntToStr(i);


Cells[11,1]:= ' ' + IntToStr(H);
// output time zones east of Greenwich
Cells[12,1]:= ' ' + IntToStr(ttt(H,1));
Cells[13,1]:= ' ' + IntToStr(ttt(H,2));
Cells[14,1]:= ' ' + IntToStr(ttt(H,3));
Cells[15,1]:= ' ' + IntToStr(ttt(H,4));
Cells[16,1]:= ' ' + IntToStr(ttt(H,5));
Cells[17,1]:= ' ' + IntToStr(ttt(H,6));
Cells[18,1]:= ' ' + IntToStr(ttt(H,7));
Cells[19,1]:= ' ' + IntToStr(ttt(H,8));
Cells[20,1]:= ' ' + IntToStr(ttt(H,9));
Cells[21,1]:= ' ' + IntToStr(ttt(H,10));
Cells[22,1]:= ' ' + IntToStr(ttt(H,11));
Cells[23,1]:= ' ' + IntToStr(ttt(H,12));
end;


end;


procedure TForm1.FormCreate(Sender: TObject);
var
SystemTime: TSystemTime;
H, M, S: word;
begin
with sg do begin
Cells[0,0]:= ' -11';
Cells[1,0]:= ' -10';
Cells[2,0]:= ' -9';
Cells[3,0]:= ' -8';
Cells[4,0]:= ' -7';
Cells[5,0]:= ' -6';
Cells[6,0]:= ' -5';
Cells[7,0]:= ' -4';
Cells[8,0]:= ' -3';
Cells[9,0]:= ' -2';
Cells[10,0]:= ' -1';
Cells[11,0]:= ' 0';


Cells[12,0]:= ' +1';
Cells[13,0]:= ' +2';
Cells[14,0]:= ' +3';
Cells[15,0]:= ' +4';
Cells[16,0]:= ' +5';
Cells[17,0]:= ' +6';
Cells[18,0]:= ' +7';
Cells[19,0]:= ' +8';
Cells[20,0]:= ' +9';
Cells[21,0]:= ' +10';
Cells[22,0]:= ' +11';
Cells[23,0]:= ' +12';
end;
lb1.Caption:= TimeToStr(Time);
GetSystemTime(SystemTime);
//SystemTimeToDateTime
end;


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


end.

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

peter
29.06.13, 23:32

thanks a lot.

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS