0

IndyTCPServerと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;

ただし、Disconnectイベントでは、ハンドルはすでに空です(401xxxxxであるため、最後の整数)。

アイデア?

4

1 に答える 1

5

使用しているDelphiまたはIndyのバージョンについては言及していませんが、D2010およびIndy 10.xには次のことが当てはまります。

クライアントの識別に「AContext.Data」プロパティを使用しました。私は通常、そこにオブジェクトを作成し、切断イベントが発生したときにそれを解放します。

新しい OnConnect() コード:

procedure TfrmMain.serverIndyConnect(AContext: TIdContext);
begin
  AContext.Data := TMyObject.Create(NIL);
  // Other Init code goes here, including adding the connection to the grid
end;

以下の 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;
于 2010-05-18T09:33:15.907 に答える