2006. március 6., hétfő

How to iterate through a parent's child controls and enable/ disable them


Problem/Question/Abstract:

I have a question about disabling containers. In my case I have a panel containing a button. When disabling the panel the button is disabled, but not greyed. Why is it not greyed?

Answer:

You have several options. Perhaps the easiest is to use this small routine which iterates through a parent's children controls, enabling / disabling each in turn:


procedure EnableContainer(Parent: TWinControl; AEnabled: Boolean);
var
  I: Integer;
begin
  for I := 0 to Parent.ControlCount - 1 do
    Parent.Controls[I].Enabled := AEnabled;
  Parent.Enabled := AEnabled;
end;


So instead of doing this:


Panel1.Enabled := False;


do this instead:


EnableContainer(Panel1, False);

Nincsenek megjegyzések:

Megjegyzés küldése