lunicirus,
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Button2: TButton;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Control : Array[1..6] of TComponent;
i : Integer;
begin
Control[1] := Label1;
Control[2] := Label2;
Control[3] := Label3;
Control[4] := Edit1;
Control[5] := Edit2;
Control[6] := Edit3;
for i := 1 to 6 do
begin
if Control[i] is TLabel Then TLabel(Control[i]).Enabled := True;
if Control[i] is TEdit Then TEdit(Control[i]).Enabled := True;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Control : Array[1..6] of TComponent;
i : Integer;
begin
Control[1] := Label1;
Control[2] := Label2;
Control[3] := Label3;
Control[4] := Edit1;
Control[5] := Edit2;
Control[6] := Edit3;
for i := 1 to 6 do
begin
if Control[i] is TLabel Then TLabel(Control[i]).Enabled := False;
if Control[i] is TEdit Then TEdit(Control[i]).Enabled := False;
end;
end;
end.
El código anterior permite asignar de forma manual que controles queremos gestionar por medio de un arreglo de controles para permitir habilitar y desabilitar los mismos.
Revisa las siguientes propiedades y métodos de controles:
Cita:
Propiedad Components : Matriz que contiene todos los componentes de un Form (Matriz de Punteros a Componentes).
Propiedad ComponentCount : Devuelve el número total de componentes de un Form.
Propiedad ComponentIndex: Índice de cada componente en la Matriz Components, permite accesar un componente por su índice.
Método FindComponent() : Permite accesar un Componente por su nombre.
|
Las anteriores propiedades y métodos son útiles para gestionar todos los componentes de un Form, ejemplo:
Código Delphi
[-]
procedure TForm1.Button3Click(Sender: TObject);
var
Control : TComponent;
i : Integer;
begin
for i := 0 to form1.ComponentCount - 1 do
begin
Control := FindComponent('Label' + IntToStr(i));
if Control is TLabel then TLabel(Control).Enabled := False;
Control := FindComponent('Edit' + IntToStr(i));
if Control is TEdit then TEdit(Control).Enabled := False;
end;
end;
Otra forma de hacer lo mismo que el código anterior:
Código Delphi
[-]
procedure TForm1.Button4Click(Sender: TObject);
var
i : Integer;
begin
for i := 0 to form1.ComponentCount - 1 do
begin
if Components[i] is TLabel then TLabel(Components[i]).Enabled := False;
if Components[i] is TEdit then TEdit(Components[i]).Enabled := False;
end;
end;
Espero sea útil
Nelson.