Delphi通過網絡同步時間的功能,功能方面類似於Windows系統時間設置面板中的同步服務器時間,這個界面有些粗糙哈,截圖如下所示:
Delphi同步網絡服務器時間代碼:
01
unit
DTDem;
02
interface
03
uses
04
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
05
StdCtrls, Psock, NMDayTim, ExtCtrls, ComCtrls, ScktComp;
06
type
07
TForm1 =
class
(TForm)
08
Panel1: TPanel;
09
Edit1: TEdit;
10
Edit2: TEdit;
11
Label1: TLabel;
12
Label2: TLabel;
13
NMDayTime1: TNMDayTime;
14
Button1: TButton;
15
Label3: TLabel;
16
StatusBar1: TStatusBar;
17
procedure
Button1Click(Sender: TObject);
18
NMDayTime1Connect(Sender: TObject);
19
NMDayTime1Disconnect(Sender: TObject);
20
NMDayTime1HostResolved(Sender: TComponent);
21
NMDayTime1Status(Sender: TComponent; Status:
String
);
22
NMDayTime1ConnectionFailed(Sender: TObject);
23
NMDayTime1InvalidHost(
var
handled:
Boolean
24
private
25
{ Private declarations }
26
public
27
{ Public declarations }
28
end
;
29
const
30
StdCap =
'The Current Date and Time is : '
31
32
Form1: TForm1;
33
implementation
34
{$R *.DFM}
35
TForm1
.
36
begin
37
NMDayTime1
ReportLevel := Status_Basic;
38
// NMDayTime1.TimeOut := 300;
39
Host := Edit1
Text;
40
Port := StrToInt(Edit2
Text);
41
Label3
Caption := StdCap+NMDayTime1
DayTimeStr;
42
43
44
45
StatusBar1
SimpleText :=
'Connected'
46
47
48
49
If
StatusBar1 <>
nil
then
50
'disconnected'
51
52
53
54
'Host resolved'
55
56
57
58
59
SimpleText := status;
60
61
62
63
ShowMessage(
'Connection Failed'
64
65
66
67
TmpStr:
68
69
InputQuery(
'Invalid Host!'
,
'Specify a new host:'
, TmpStr)
70
Begin
71
Host := TmpStr;
72
Handled :=
TRUE
73
End
74
75
然後我們寫一個控制台程序做試驗:program TestC
Delphi Firemonkey TListView 提供
本例效果圖:unit Unit1; interface
本例效果圖:代碼文件:unit Unit1;i