我将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;
也不行啊
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;
也不行啊
解决方案 »
- 各位大侠,谁知道过滤黄色网站或其他不良网站的原理是什么啊?
- 【求助】一个女生朋友过几天就要过生日,该送什么好呢?☆★☆★☆★
- 做机械控制,已经有API提供。。。。
- 高手们做安装程序怎么做?
- 有用吗?比Delphi原始函数快近3倍的的sin()和cos()
- sql语句查询输入问题
- 在Install shield中,如何把一个目录一次性放入安装文件中。而不是现在的一个一个添文件目录。
- 如何将MEMO中的文件保存为TXT文件,可否给个例子
- 问一个问题,先来的先给分!!!很简单。。。。。快来拿分啊
- 各位仁兄指点一下:在何处可以下载到KYLIX2。0企业版软件??
- 一个关于在Tlist中存储Tlist的问题
- 已经考上研究生,又招到了一份很好的工作,我该如何选择?
判断 如果有连接的话
CanClose := False 窗口就关闭不了了
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;