connectionlist acConnectionList component
Hierarchy Properties Methods Events
Return to Introduction  Previous page  Next page
Overview
The acConnectionList retrieves the list of all active Internet connection and returns information in the form similar to NetStat tool. You can retrieve the list using Refresh method and get access to the information about each connection, using the component as usual TList, with objects which contains detailed information about connection (local and remote port and host name, protocol, and even possible software behind the protocol).  

How does it works and how to use?
The component is the container of the list of TacConnection objects. Each TacConnection object contains brief information about the currently established TCP or UDP connection (it's local and remote IP address and port number, connection state, protocol type, etc).  
 
The acConnectionList component automatically contains the list of currently available connections when your application starts. However, to keep the list fresh, you should call Refresh method, so the component will re-retreive the list of active connections.  
 
tip Following example demonstrates how to retrieve the list of processes and display them in the ListView:  
procedure TForm1.Button1Click(Sender: TObject);  
var  
  I: Integer;  
  ListItem: TListItem;  
begin  
  acConnectionList1.Refresh// refreshing the list of processes  
 
  ListView1.Items.BeginUpdate;  
  try  
    ListView1.Items.Clear;  
    I := acConnectionList1.Count;  
    if I <> 0 then  
     for I := 0 to I - 1 do  
      begin  
       ListItem := ListView1.Items.Add;  
         ListItem.Caption := acConnectionList1[I].LocalIPStr + IntToStr(LocalPort));  
       ListItem.SubItems.Add(acConnectionList1[I].RemoteIPStr + IntToStr(RemotePort));  
 
       // ...optionally, let's associate the Data pointer to TacConnection object  
       // and Data pointer of Connection object to ListItem  
       ListItem.Data := acConnectionList1[I];  
       acConnectionList1[I].Data := ListItem;  
      end;  
  finally  
    ListView1.Items.EndUpdate;  
  end;  
end;  
 
// This code demonstrates how to display the Remote IP address and port  
// when user selects the list item of ListView  
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;  
  Selected: Boolean);  
begin  
  if Item <> nil then  
   with TacConnection(Item.Data) do  
    Label1.Caption := LocalIPStr + ':' + IntToStr(LocalPort);  
end;  

See also
acProcessList and acHostnameResolver components.