processlist acProcessList component
Hierarchy Properties Methods
Return to Introduction  Previous page  Next page
Overview
The acProcessList component used to retrieve the list of all running system processes. You can retrieve the full list simly calling the Refresh method and gain access to the information about each process, using the component as usual TList. TacProcess objects contains the information about process and has Kill method which able to imediately terminate the process.  

How does it works and how to use?
The component is the container of the list of TacProcess objects. Each TacProcess object contains brief information about the process (it's executable file name, description, application type, process identifier, icon index in the system image list and the list of windows which belongs to the process). Also, the TacProcess object allows to terminate the process using its Kill method.  
 
The acProcessList component already contains the list of currently running processes when your application starts. However, to keep the list fresh, you should call Refresh method, so the component will re-retreive the list of current processes.  
 
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  
  acProcessList1.Refresh// refreshing the list of processes  
 
  ListView1.Items.BeginUpdate;  
  try  
    ListView1.Items.Clear;  
    I := acProcessList1.Count;  
    if I <> 0 then  
     for I := 0 to I - 1 do  
      begin  
       ListItem := ListView1.Items.Add;  
       ListItem.Caption := acProcessList1[I].ExeName;  
       ListItem.ImageIndex := acProcessList1[I].SystemIconIndex;  
       ListItem.SubItems.Add(acProcessList1[I].Description);  
 
       // ...optionally, let's associate the Data pointer to TacProcess object  
       // and Data pointer of Process object to ListItem  
       ListItem.Data := acProcessList1[I];  
       acProcessList1[I].Data := ListItem;  
      end;  
  finally  
    ListView1.Items.EndUpdate;  
  end;  
end;  
 
// This code demonstrates how to display the process description and its 32x32 icon  
// when user selects the list item of ListView  
procedure TForm1.ListView1SelectItem(Sender: TObject; Item: TListItem;  
  Selected: Boolean);  
begin  
  if Item <> nil then  
   with TacProcess(Item.Data) do  
    begin  
     Label1.Caption := Description;  
     Image1.Picture.Icon.Handle := SystemIcon32Handle;  
    end;  
end;  

See also
acConnectionList component.