2006. augusztus 25., péntek

Remove all components of a certain type at run time


Problem/Question/Abstract:

How to remove all components of a certain type at run time

Answer:

//implementation:

procedure Tform1.freeInstances(aClass: TClass);
var
  i: Integer;
begin
  for i := formFacture.ControlCount - 1 downto 0 do
    if (Controls[i] is aClass) then
    begin
      (Controls[i] as aClass).Free;
        //instead of free you can put anything you need here
    end;
end;

//calling:

procedure Tform1.Button1Click(Sender: TObject);
begin
  freeInstances(TEdit); //will free all tedit on form1
end;

Nincsenek megjegyzések:

Megjegyzés küldése