Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi Indy TCP服务器-已删除断开连接的句柄?_Delphi_Indy - Fatal编程技术网

Delphi Indy TCP服务器-已删除断开连接的句柄?

Delphi Indy TCP服务器-已删除断开连接的句柄?,delphi,indy,Delphi,Indy,我有一个带有Indy TCPServer和TCPClient的Delphi应用程序。我使用AContext.Bindind.Handle标识每个连接(错误?) 因此,我有一个显示连接的网格,我将在断开连接后删除该条目: procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext); var I:Integer; begin for I := 0 to gridClients.RowCount - 1 do begin if gri

我有一个带有Indy TCPServer和TCPClient的Delphi应用程序。我使用
AContext.Bindind.Handle
标识每个连接(错误?)

因此,我有一个显示连接的网格,我将在断开连接后删除该条目:

procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
for I := 0 to gridClients.RowCount - 1 do
begin
  if gridClients.Cells[0, I] = IntToStr(AContext.Binding.Handle) then
  begin
     gridClients.Rows[I].Delete(I);
  end;
end;

WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;
但是在断开连接事件中,句柄已经是空的(它曾经是401xxxxx,所以是最后一个整数)


想法?

您没有提到您使用的是哪个版本的Delphi或Indy,但以下内容适用于D2010和Indy 10.x

我使用了“AContext.Data”属性来标识客户机。我通常在那里创建一个对象,并在断开连接事件发生时释放它

新的OnConnect()代码:

修改了以下OnDisconnect()代码:

procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
  for I := 0 to gridClients.RowCount - 1 do
  begin
    if gridClients.Cells[0, I] = IntToStr(AContext.Data) then
    begin
      gridClients.Rows[I].Delete(I);
    end;
 end;
 WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;

您没有提到您使用的是哪个版本的Delphi或Indy,但以下内容适用于D2010和Indy 10.x

我使用了“AContext.Data”属性来标识客户机。我通常在那里创建一个对象,并在断开连接事件发生时释放它

新的OnConnect()代码:

修改了以下OnDisconnect()代码:

procedure TfrmMain.serverIndyDisconnect(AContext: TIdContext);
var I:Integer;
begin
  for I := 0 to gridClients.RowCount - 1 do
  begin
    if gridClients.Cells[0, I] = IntToStr(AContext.Data) then
    begin
      gridClients.Rows[I].Delete(I);
    end;
 end;
 WriteLogEntry('Connection closed... (' + AContext.Binding.PeerIP+')');
end;

好建议。始终使用您自己的标识符,不要将Indy的内部对象和句柄用作ID。好建议。始终使用您自己的标识,不要将Indy的内部对象和句柄用作标识。