zoukankan      html  css  js  c++  java
  • delphi循环遍历同类控件或所有控件

    循环遍历同类控件:

    form1中有groupbox1,内有多个speedbutton,控制其同时按下。

    var i:integer;

    begin

    for i:=0 to form1.groupbox1.controlcount-1 do

    if form1.groupbox1.controls[i] is tspeedbutton then

    begin

    tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

    ‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

    tspeedbutton(form1.groupbox1.controls[i]).down:=true;

    end;

    结合数据库使用,表示表rz中的rz字段(bit),为1则按下,为0则抬起。

    var i:integer;

    begin

    i:=0;

    while not adotable1.eof then

    if adotable1.fields[1].asboolen=true then

    begin

    tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

    ‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

    tspeedbutton(form1.groupbox1.controls[i]).down:=true;

    end

    else‍

    begin

    tspeedbutton(form1.groupbox1.controls[i]).allow‍allup:=true;

    ‍tspeedbutton(form1.groupbox1.controls[i]).groupindex:=i+1;

    tspeedbutton(form1.groupbox1.controls[i]).down:=false;

    end;

    inc(i);

    adotable1.next;

    end;

    遍历Panel组件上的所有控件:

    procedure frmMain.CLS; //主窗体自定义事件CLS
    var i:integer;
    begin
      for i:=0 to panel5.ControlCount -1 do
      begin
        if panel5.Controls[i] is TEdit then  //Edit组件
        begin
           ((panel5.Controls[i]) as TEdit).Text:='';
           ((panel5.Controls[i]) as TEdit).Enabled:=true;
        end  else if panel5.Controls[i] is TComboBox then  //ComboBox组件
          begin
             ((panel5.Controls[i]) as TComboBox).Text:='';
             ((panel5.Controls[i]) as TComboBox).Enabled:=true;
          end  else if panel5.Controls[i] is TDateTimePicker then  //DateTimePicker组件
            begin
              ((panel5.Controls[i]) as TDateTimePicker).Enabled:=true;
              ((panel5.Controls[i]) as TDateTimePicker).DateTime:=now();
            end; 
        end;
    end;
    这个过程主要是清空panel5组件Edit、ComboBox组件Text内容、把DateTimePicker组件日期设为当前日期,并使panel5所有控件可用 ......


  • 相关阅读:
    后缀数组板子
    上海高校金马五校赛 J
    西安电子科技大学第16届程序设计竞赛网络同步赛 G-小国的复仇
    HDU
    string 与char* char[]之间的转换 .
    (分治思想)(归并排序)C
    如何取出 Map中key和value的值
    C++ STL 中 map 容器的说明和使用技巧 .
    (经典map)A
    Babelfish(6.1.2)(sort结构体排序)(sscanf()基本使用方法)(二分法)
  • 原文地址:https://www.cnblogs.com/ntearn/p/1996708.html
Copyright © 2011-2022 走看看