遍历窗体中的控件

遍历窗体中的控件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 .

 

转载于:https://www.cnblogs.com/Jekhn/archive/2010/12/27/1917806.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值