📄 nmdaytim.pas
字号:
unit NMDayTim;
{$X+}
{$R-}
{$IFDEF VER100}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER110}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER120}
{$DEFINE NMF3}
{$ENDIF}
{$IFDEF VER125}
{$DEFINE NMF3}
{$ENDIF}
interface
uses
SysUtils, Classes, Forms, Psock, Winsock, NMConst;
{$IFDEF VER110}
{$OBJEXPORTALL On}
{$ENDIF}
{$IFDEF VER120}
{$OBJEXPORTALL On}
{$ENDIF}
{$IFDEF VER125}
{$OBJEXPORTALL On}
{$ENDIF}
// CompName='TNMdayTim';
// Major_Version='4';
// Minor_Version='02';
// Date_Version='012798';
type
TNMDayTime = class(TPowerSock)
private
function GetTimeStr: string;
protected
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
property DayTimeStr: string read GetTimeStr;
published
end;
implementation
constructor TNMDayTime.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Port := 13;
TimeOut := 500;
end;
function TNMDayTime.GetTimeStr: string;
var i, ct: integer;
handled: boolean;
begin
BeenCanceled := FALSE; {Turn Canceled off}
if FConnected then {If already connected raise exception}
raise ESockError.Create(sPSk_Cons_msg_Conn);
ct := 0;
repeat
try
ResolveRemoteHost; {Resolve the IP address of remote host}
except
on E: ESockError do
if (E.Message = sPSk_Cons_msg_host_to) or (E.Message = sPSk_Cons_msg_host_Can) then raise;
end;
if RemoteAddress.sin_addr.S_addr = 0 then
if ct > 0 then raise ESockError.Create(sPSk_Cons_msg_add_null) {If Resolving failed raise exception}
else
if not Assigned(OnInvalidHost) then raise ESockError.Create(sPSk_Cons_msg_add_null)
else
begin
handled := FALSE;
OnInvalidHost(handled);
if not handled then raise ESockError.Create(sPSk_Cons_msg_add_null); {If Resolving failed raise exception}
ct := ct + 1;
end;
until RemoteAddress.sin_addr.S_addr <> 0;
StatusMessage(Status_Debug, sPSk_Cons_msg_Conning); {Inform Status}
RemoteAddress.sin_family := AF_INET; {Make connected true}
{$R-}
if Proxy = '' then
RemoteAddress.sin_port := htons(Port) {If no proxy get port from Port property}
else
RemoteAddress.sin_port := htons(ProxyPort); {else get port from ProxyPort property}
{$R+}
i := SizeOf(RemoteAddress); {i := size of remoteaddress structure}
{Connect to remote host}
succeed := FALSE;
Timedout := FALSE;
TimerOn;
Winsock.Connect(ThisSocket, RemoteAddress, i);
repeat
application.processmessages; {Process messages till response received}
until succeed or Timedout; {Responce received, Timed out or Cancelled exits loop}
TimerOff;
if Timedout then raise Exception.Create(Cons_Msg_ConnectionTimedOut);
try
while not DataAvailable do
application.processmessages;
Result := Read(0);
finally
Disconnect;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -