procedure TForm1.socket1ClientConnect(Sender: TObject;Socket:TCustomWinSocket);
var
L: TListItem;
begin
L:= Listview1.Items.Add;
l.SubItems.Add(Socket.RemoteHost, socket);
end;
这是我用来删除的代码:(仅当我发送命令靠近客户端时才有效)。:
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject;Socket: TCustomWinSocket);
var
L:TlistItem;
begin
Listview1.findcaption(0,inttostr(socket.handle),false,true,false,);
if L <> nil then
l.delete;
end;
答案 0 :(得分:0)
您没有在TListItem.Caption
中添加任何价值,但您尝试使用FindCaption()
,就像您拥有的那样。我建议将TCustomWinSocket
对象指针放在TListItem.Data
中,然后使用FindData()
代替:
procedure TForm1.ServerSocket1ClientConnect(Sender: TObject; Socket: TCustomWinSocket);
var
L: TListItem;
begin
L := Listview1.Items.Add;
L.SubItems.Add(Socket.RemoteHost);
L.Data := Socket;
end;
procedure TForm1.ServerSocket1ClientDisconnect(Sender: TObject; Socket: TCustomWinSocket);
var
L: TListItem;
begin
L := ListView1.FindData(0, Socket, true, false);
if L <> nil then
L.Delete;
end;