我将idTcpServer.Active设定为true后,一个客户端连接上来了,但是我在客户端没有断开连接的情况下,是不能关闭程序的,我在Server的FormClose中加入了
 TCPServer.Threads.LockList;
    for i := 0 to TCPServer.Threads.LockList.Count- 1 do
      begin
            Athread :=TCPServer.Threads.LockList.Items[i];        
            if not Athread.Terminated then
               Athread.Terminate;
            if Athread.Connection.Connected then
              Athread.Connection.Disconnect;  
            AThread.Data := nil;
            TCPServer.Threads.LockList.Remove(Athread);
      end;
  TCPServer.Threads.UnlockList;
  TCPServer.Active := false;
也不行啊

解决方案 »

  1.   

    OnDisconnect消息处理可能有问题。
      

  2.   

    在onclosequery里面写
    判断 如果有连接的话  
    CanClose := False  窗口就关闭不了了
      

  3.   

    procedure Tfrm_ServerMain.TCPServerConnect(AThread: TIdPeerThread);
    begin
      MyList.LockList.Add(Pointer(AThread));
      MyList.UnlockList;
      AThread.FreeOnTerminate := True;
    end;procedure Tfrm_ServerMain.TCPServerDisconnect(AThread: TIdPeerThread);
    begin
      i := MyList.LockList.IndexOf(Pointer(AThread));
      MyList.UnlockList;
      MyList.LockList.Remove(Pointer(AThread));
      MyList.UnlockList;
    end;
    procedure Tfrm_ServerMain.BitBtn2Click(Sender: TObject);       //强制关闭所有线程
    var
      i,j : integer;
    begin
      lbxUser.Items.Clear;
      j := MyList.LockList.Count;
      MyList.UnlockList;
      if j > 0 then
      begin
        for i := 0 to j -1 do
        begin
          TIdPeerThread(MyList.LockList.Items[i]).Connection.Disconnect;
          MyList.UnlockList;
        end;
      end;
    end;