代码一,
begin 
Application.ProcessMessages;
if ( Now - TmpTime ) > 5 / 86400 then  break;
end;
代码二:
if self.CMPP3Socket.Socket.SendBuf(PK_TERMINATE,SizeOf(PK_TERMINATE)) = SizeOf(PK_TERMINATE) then 
begin
.
.
.
end

解决方案 »

  1.   

    Application.ProcessMessages; //应用程序消息处理
    if ( Now - TmpTime ) > 5 / 86400 then  break; //当前时间和tmptime时间相减大于5 / 86400 退出循环
    end; 
      

  2.   

    代码二是用Socket发送信息。
    用法:SendBuf(要发送的内容,要发送内容的长度)
    函数SendBuf的参数:
      PK_TERMINATE: 发送内容
      SizeOf(PK_TERMINATE):要发送内容的长度
    函数SendBuf如果执行难成功,则返回值为发送内容的长度。所以 if self.CMPP3Socket.Socket.SendBuf(PK_TERMINATE,SizeOf(PK_TERMINATE)) = SizeOf(PK_TERMINATE) then 
    意思就是如果发送PK_TERMINATE成功就执行  begin 与 end 之间的代码。
      

  3.   

    所以 if self.CMPP3Socket.Socket.SendBuf(PK_TERMINATE,SizeOf(PK_TERMINATE)) = SizeOf(PK_TERMINATE) then 
    意思就是如果发送PK_TERMINATE成功就执行  begin 与 end 之间的代码。
    那=SizeOf(PK_TERMINATE)啥意思?
    为什么要做比较?
      

  4.   

    如果发送错误 sendbuf的结果不一定=SizeOf(PK_TERMINATE)
    delphi帮助内容:
    Delphi syntax:function SendBuf(var Buf; Count: Integer): Integer;C++ syntax:int __fastcall SendBuf(void *Buf, int Count);DescriptionUse SendBuf to write to the socket connection. Call this method from the OnSocketEvent event handler of a Windows socket object or in the OnWrite or OnClientWrite event handler of a socket component. Alternately, Use SendBuf to write when a connection is first formed when the socket does not expect notification that the socket on the other end of the connection is expecting to read.For non-blocking sockets, the data is sent to the WinSock DLL which has it's own internal buffers. If the WinSock can accept additional data, SendBuf returns immediately with the number of bytes queued. If the WinSock internal buffer space is not able to accept the buffer being sent, SendBuf returns -1 and no data is queued at all. In this case, wait a bit for the WinSock to have a chance to send out already-queued data; then try again.For blocking sockets, SendBuf returns the number of bytes actually written. If an error occurs while writing to the connection, SendBuf terminates the connection and raises an ESocketError exce
      

  5.   

    不比较,你怎么知道你发送成功没有啊?
    你用SendBuf发送内容,不就是为了对方也能正确的收到信息吗?
    你通过判断 知道自己这边发送成功了, 再执行后面的代码,这是很正常的逻辑思维啊!
    当然你也可以判断之后,如果失败你也可以再做一些其他的补救工作(报错啊,或者再次发送啊)!  
      

  6.   

    代码1:为防止在大循环里,界面死掉(循环中间做ProcessMessages会及时的处理消息队列里的消息)
    代码2:发送PK_TERMINATE里的数据,成功执行后面的结果.因为sendbuf可能失败而返回0,而不是实际你要发送数据的长度