zoukankan      html  css  js  c++  java
  • 遍历窗体中的控件

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

  • 相关阅读:
    再见 2020, 愿“山河无恙,人间皆安”| 年终总结
    Oracle
    Linux安装
    线程池
    AutoJS
    VSCode
    c++ 解析yaml文件
    管道: 哪些命令能直接从管道的输出中读取?
    K8S 集群部署
    Android项目实战(六十一):pdf文件用图片方式预览
  • 原文地址:https://www.cnblogs.com/Jekhn/p/1917806.html
Copyright © 2011-2022 走看看