Mega Code Archive

 
Categories / Delphi / Examples
 

Find out the number of total components

Title: Find out the number of total components Question: Is there a way of checking how many components exist (at runtime) for the entire application without having to run through every other components ComponentCount property. Answer: Every form that is in existence is stored in Screen.Forms, which is an array of Forms. Every form has a ComponentCount. function GetTotalComponents : Integer; var TotalComps, CurForm : Integer; begin TotalComps := 0; for CurForm := 0 to (Screen.FormCount - 1) do begin TotalComps := TotalComps + Screen.Forms[CurForm].ComponentCount; end; Result := TotalComps; end;