遍历窗体中的控件

遍历窗体中的控件Form.Components

代码
//last updated by Ming 2009-02-05
unit unitCommon;

interface

uses
SysUtils, ComCtrls, Controls, Classes, Forms, StdCtrls,
Graphics, ExtCtrls;

{Common Method}
procedure ClearContainer(Form: TForm); overload;
procedure ClearContainer(Form,Panel: TControl); overload;
procedure AddStatus(Form: TForm;pColor: TColor); overload;
procedure AddStatus(Control: TControl;pColor: TColor); overload;
procedure AddStatus(Control,Panel: TControl;pColor: TColor);overload;
procedure EditStatus(Form: TForm;pColor: TColor);overload;
procedure EditStatus(Control,Panel: TControl;pColor: TColor);overload;
procedure SaveStatus(Form: TForm;pColor: TColor);overload;
procedure SaveStatus(Control,Panel: TControl;pColor: TColor);overload;
procedure CancelStatus(Form: TForm;pColor: TColor);overload;
procedure CancelStatus(Control,Panel: TControl;pColor: TColor);overload;
function CheckEditNullStatus(Form: TForm): Boolean;overload;
function CheckEditNullStatus(Form,Panel: TControl): Boolean;overload;

implementation

procedure AddStatus(Form: TForm;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Enabled :
= True;
TEdit(ChildControl).Color :
= pColor;
end
else if ChildControl is TButton then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker then
TDateTimePicker(ChildControl).Enabled :
= true;
end;
end;

procedure AddStatus(Control: TControl;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Control.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Control.Components[i];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Enabled :
= True;
TEdit(ChildControl).Color :
= pColor;
end
else if ChildControl is TButton then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker then
TDateTimePicker(ChildControl).Enabled :
= true;
end;
end;

procedure AddStatus(Control,Panel: TControl;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Control.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Control.Components[i];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Enabled :
= True;
TEdit(ChildControl).Color :
= pColor;
end
else if ChildControl is TButton and (TForm((ChildControl as TButton).Parent) = Panel) then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker and (TForm((ChildControl as TDateTimePicker).Parent) = Panel) then
TDateTimePicker(ChildControl).Enabled :
= true;
end;
end;

procedure EditStatus(Form: TForm;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= True;
end
else if ChildControl is TButton then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker then
TDateTimePicker(ChildControl).Enabled :
= true;
end;
end;

procedure EditStatus(Control,Panel: TControl;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Control.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Control.Components[i];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= True;
end
else if ChildControl is TButton and (TForm((ChildControl as TButton).Parent) = Panel) then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker and (TForm((ChildControl as TDateTimePicker).Parent) = Panel) then
TDateTimePicker(ChildControl).Enabled :
= true;
end;
end;

procedure SaveStatus(Form: TForm;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= False;
end
else if ChildControl is TButton then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker then
TDateTimePicker(ChildControl).Enabled :
= False;
end;
end;

procedure SaveStatus(Control,Panel: TControl;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Control.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Control.Components[i];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= False;
end
else if ChildControl is TButton and (TForm((ChildControl as TButton).Parent) = Panel) then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker and (TForm((ChildControl as TDateTimePicker).Parent) = Panel) then
TDateTimePicker(ChildControl).Enabled :
= False;
end;
end;

procedure CancelStatus(Form: TForm;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= False;
end
else if ChildControl is TButton then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker then
TDateTimePicker(ChildControl).Enabled :
= False;
end;
end;

procedure CancelStatus(Control,Panel: TControl;pColor: TColor);
var
ChildControl: TComponent;
i: Integer;
begin
for i := Control.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Control.Components[i];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Color :
= pColor;
TEdit(ChildControl).Enabled :
= False;
end
else if ChildControl is TButton and (TForm((ChildControl as TButton).Parent) = Panel) then
TButton(ChildControl).Enabled :
= False
else if ChildControl is TDateTimePicker and (TForm((ChildControl as TDateTimePicker).Parent) = Panel) then
TDateTimePicker(ChildControl).Enabled :
= False;
end;
end;

function CheckEditNullStatus(Form: TForm): Boolean;
var
ChildControl: TComponent;
i: Integer;
begin
Result :
= True;
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit then
begin
if TEdit(ChildControl).Text = '' then
begin
Result :
= false;
TEdit(ChildControl).SetFocus;
break;
end;
end;
end;
end;

function CheckEditNullStatus(Form,Panel: TControl): Boolean;
var
ChildControl: TComponent;
i: Integer;
begin
Result :
= True;
for i := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[i];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
if TEdit(ChildControl).Text = '' then
begin
Result :
= false;
TEdit(ChildControl).SetFocus;
break;
end;
end;
end;
end;

procedure ClearContainer(Form: TForm);
var
ChildControl: TComponent;
iLoop: Integer;
begin
for iLoop := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[iLoop];
if ChildControl is TEdit then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Color :
= clWindow;
end
else if ChildControl is TComboBox then
begin
TComboBox(ChildControl).Clear;
TComboBox(ChildControl).Color :
= clWindow;
end
else if ChildControl is TListBox then
TListBox(ChildControl).Clear
else if ChildControl is TListView then
TListView(ChildControl).Clear
else if ChildControl is TCheckBox then
TCheckBox(ChildControl).Checked :
= False;
end;
end;

procedure ClearContainer(Form,Panel: TControl);
var
ChildControl: TComponent;
iLoop: Integer;
begin
for iLoop := Form.ComponentCount - 1 downto 0 do
begin
ChildControl :
= Form.Components[iLoop];
if ChildControl is TEdit and (TForm((ChildControl as TEdit).Parent) = Panel) then
begin
TEdit(ChildControl).Text :
= '';
TEdit(ChildControl).Color :
= clWindow;
end
else if ChildControl is TComboBox and (TForm((ChildControl as TComboBox).Parent) = Panel) then
begin
TComboBox(ChildControl).Clear;
TComboBox(ChildControl).Color :
= clWindow;
end
else if ChildControl is TListBox and (TForm((ChildControl as TListBox).Parent) = Panel) then
TListBox(ChildControl).Clear
else if ChildControl is TListView and (TForm((ChildControl as TListView).Parent) = Panel) then
TListView(ChildControl).Clear
else if ChildControl is TCheckBox and (TForm((ChildControl as TCheckBox).Parent) = Panel) then
TCheckBox(ChildControl).Checked :
= False;
end;
end;

end.

 

posted @ 2010-12-27 11:39  Jekhn  阅读(322)  评论(0编辑  收藏  举报