Código
procedure EnableDisableControls(Form: TForm; ClassComponents: array of TControlClass; Exclude: array of TControl; State: Boolean);
var
i,
j,
z: Integer;
begin
for I := 0 to Form.ComponentCount -1 do
for j := Low(ClassComponents) to High(ClassComponents) do
if High(Exclude) > -1 then
begin
for z := Low(Exclude) to High(Exclude) do
if (Form.Components[i] is ClassComponents[j]) and (Form.Components[i] <> Exclude[z]) then (Form.Components[i] as ClassComponents[j]).Enabled := State;
end
else
if (Form.Components[i] is ClassComponents[j]) then (Form.Components[i] as ClassComponents[j]).Enabled := State;
end;
Exemplo de uso:
EnableDisableControls(Form1, [TEdit, TMemo, TCheckBox, TRadioButton], [CheckBox1], (not Edit2.Enabled));
Neste exemplo acima todos os edits, memos, checkboxes e radiobuttons serão desabilitados/habilitados, com exceção do checkbox1.
Planeta Delphi - www.planetadelphi.com.br - Todos os direitos reservados | Copyright 2001-2009