⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 实例——应用idtimeudpserver和tidtimeudp组件.txt

📁 Delphi 7组件应用实例 书籍语言: 简体中文 书籍类型: 程序设计 授权方式: 免费软件 书籍大小: 105 KB
💻 TXT
字号:
(1) unit U_UDPTime_Client;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient, IdTimeUDP,
  StdCtrls;
type
  TF_UDPTime_Client = class(TForm)
    Button1: TButton;
    Combobox1: TComboBox;
    lblTimeServer: TLabel;
    Label1: TLabel;
    Edit1: TEdit;
    IdTimeUDP1: TIdTimeUDP;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  F_UDPTime_Client: TF_UDPTime_Client;

implementation

{$R *.dfm}

procedure TF_UDPTime_Client.Button1Click(Sender: TObject);
begin
try
 //设置Time服务器的地址
 IdTimeUDP1.Host := Combobox1.Text;
 //显示时间
 Edit1.Text := DateTimeToStr ( IdTimeUDP1.DateTime );
except
 Showmessage('获取时间操作失败,请检查Time服务器是否活跃!');
end;
end;
end.

(2)unit U_UDPTime_Server;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer,
  IdTimeUDPServer, StdCtrls,IdSocketHandle;
type
  T_UDPTime_Server = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    IdTimeUDPServer1: TIdTimeUDPServer;
    procedure FormActivate(Sender: TObject);
    procedure IdTimeUDPServer1UDPRead(Sender: TObject; AData: TStream;
      ABinding: TIdSocketHandle);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  _UDPTime_Server: T_UDPTime_Server;
  AccessTimes:integer;

implementation

 
{$R *.dfm}

procedure T_UDPTime_Server.FormActivate(Sender: TObject);
begin
 try
 //激活TIdECHOServer组件
  IdTimeUDPServer1.Active := True;
  AccessTimes :=0;
 except
  ShowMessage('拒绝连接!由于安全的原因无法绑定到预定的端口!');
  Application.Terminate;
 end;
end;

procedure T_UDPTime_Server.IdTimeUDPServer1UDPRead(Sender: TObject;
  AData: TStream; ABinding: TIdSocketHandle);
begin
  AccessTimes :=AccessTimes +1;
  Label2.Caption :='['+inttostr(AccessTimes)+'  次]';
end;
end.


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -